# Pastebin lOfn79W1 #!/bin/bash # we check for wifistate and stop/start service based on it. WIFI_FILE='/var/run/engine/wifiState' service=engine-update function update_onwifi () { if grep -q "^up" /var/run/engine/wifiState && \ initctl status engine | grep -q "start/running" then start engine-update elif grep -q "^down" /var/run/engine/wifiState; then stop engine-update fi } #check if inotify-tools is installed type -P inotifywait &>/dev/null || { echo "inotifywait command not found."; } # it takes some time for wifi status to appear. so we read the directory for changes. while inotifywait --format '%f' -e modify,attrib,close_write,move,create,delete /var/run/engine/ ; do # file check is not as it takes some time after boot for the file to appear. if [ -f "$WIFI_FILE" ]; then # we basically chehck everytime someone touch the directory var/run/engine. update_onwifi else echo "$WIFI_FILE not found." fi done