After final judgment has been rendered in an action in which security for costs has been given, as required by this chapter, the court, on motion of any person having a right to such costs, or any part thereof, after ten days' notice of such motion, may enter judgment against the surety for the amount of the costs or so much thereof as may be unpaid. Executions may be issued on such judgment, as in other cases, for the use and benefit of the persons entitled to such costs. In the event that a cash bond has been given, the court shall, on motion of any person having a right to such costs, or any part thereof, after ten days' notice of such motion, enter judgment for the amount of costs or so much thereof as may be unpaid, and shall proceed to pay the same from the cash bond; and any surplus remaining after such costs have been paid and satisfied shall be returned to the party who posted the cash bond.