Refactor monitors shell script