#! /bin/bash if [[ "${1}" == 'start' ]] then declare -a pids cd /home/pbot ./envbot & pids[0]=$! ./pbot-ng_fixer & pids[1]=$! ./labs_change_detector & pids[2]=$! function closedown { for pid in ${pids[@]} do kill $pid done exit } trap "closedown" SIGINT SIGTERM while true do sleep 5h done elif [[ "${1}" == 'stop' ]] then while true do pid=$(pgrep -u pbot | head -1) if [[ -n "${pid}" ]] then kill ${pid} &>/dev/null else exit fi done else echo "first arg must be \`start' or \`stop'" fi