Section 40. If the office of town treasurer, town collector of taxes, town accountant or auditor in a town having but one is vacant or if any such officer, because of disability or absence, is unable to perform his duties, the selectmen may in writing signed by them or by a majority of them, which shall be filed in the office of the town clerk, appoint a temporary officer to hold such office and exercise the powers and perform the duties thereof until another is duly elected or appointed and has qualified according to law or the officer who was disabled or absent resumes his duties. Any such temporary officer shall be sworn and give bond for the faithful performance of his duties in accordance with the provisions of law applying to the officer whose place he fills, and if he fails so to do within ten days after his appointment the selectmen shall rescind the appointment and appoint another. If a tree warden, highway surveyor, or road commissioner in a town having but one road commissioner, because of disability or absence, is unable to perform his duties, the selectmen may, in like manner, appoint a temporary officer to hold his office, who shall have like powers and duties until such tree warden, highway surveyor or road commissioner resumes his duties or his successor is elected or appointed, as the case may be. This section shall not apply to cities.