(a) When property levied on under an attachment has been sold pending the action, on motion of the plaintiff, the judge of the court to which the attachment is returnable must, at any time after 30 days from the levy, make and cause to be entered upon the minutes of the court an order directing the officer having in his hands the proceeds of sale, after reserving an amount to be fixed in the order to cover the probable costs and charges in the case, to pay over to the plaintiff, or his attorney, the balance of such proceeds not exceeding the amount of the plaintiff's demand, to be stated in the order, upon his giving bond in double the amount of the money to be paid over, payable to the defendant with sufficient surety to be approved by such officer and with condition that if he is cast in the action, he will pay into court the amount so paid over to him, with interest, or if he recovers in the action, and the recovery is for a sum less than the amount so paid over to him, he will pay into court the excess, with interest. Upon the execution of such bond, such officer shall pay over to the plaintiff, or his attorney, the proceeds of sale as directed in the order. Such order shall not, however, be made if, upon the hearing of the motion or at any time prior thereto, a claim to the property levied on is interposed by any person not a party to the action, or the defendant denies under oath the existence of the plaintiff's demand. Notice of such motion and of the time and place of hearing the same must be served on the defendant, or his attorney, 10 days before the hearing thereof or, if the defendant resides out of the state and has no attorney resident of the county, such notice must be given by publication in some newspaper published in the county once a week for three successive weeks.
(b) The officer taking such bond shall forthwith return the same to the clerk of the court in which the action is pending, with his endorsement thereon, showing how he has executed such order and specifying the amount paid over to the plaintiff, or his attorney, thereunder, and the date of such payment; and, if the plaintiff does not recover in the action or if he recovers and his recovery is for a less sum than the amount paid him under such order, and he fails for 30 days after the date of the entry of the judgment to pay into court the money required by the condition of his bond to be paid, the clerk shall endorse the bond forfeited and issue execution thereon against the obligors for the amount so paid to the plaintiff, or his attorney, as shown by the endorsement of the officer taking the bond, with interest from the date of such payment, if the plaintiff did not recover in the action or, if the plaintiff recovered and his recovery was for a less sum than the amount so paid, for the difference between the amount recovered and the amount received by him, with interest from the date of payment. If the plaintiff complies with the condition of the bond by paying the money into court, the same must be paid to the defendant.