#!/bin/bash # shutdownasap version #VERSION# set -e . #ETCDIR#/shutdownasap.conf [ -r "${pidFile}" ] && ps aux | grep -q "^\S\+\s\+$(cat "${pidFile}") " && exit echo $$ > "${pidFile}" quiet=false if [ $# -eq 1 ] && [ "x$1" = 'x-q' ]; then quiet=true elif [ $# -ne 0 ]; then >&2 echo 'usage: shutdownasap [-q]' exit 1 fi beforeWatchHook i=1 while [ ${i} -gt 0 ] do sleep 1 prozesse="$(ps aux | grep -v grep)" nochwarten=false if [ -d "${waitForDir}" ] && ls -1A "${waitForDir}" | grep -q "." then nochwarten=true if ! ${quiet}; then echo ".warteauf: " ls -1A "${waitForDir}" fi fi if users | grep -q "." then nochwarten=true if ! ${quiet}; then echo -n "users: " users fi fi for synActFile in /sys/block/md*/md/sync_action do if [ -r "${synActFile}" ] && ! grep -q "^idle\$" "${synActFile}" then nochWarten=true if ! ${quiet}; then echo -n "raid ${synActFile}: " cat "${synActFile}" fi fi done for s in "${!shutDownNoGoProcesses[@]}" do if echo "${prozesse}" | grep -q "\(\s\|/\)${shutDownNoGoProcesses[${s}]}\(\$\|\s\)" then nochwarten=true if ! ${quiet}; then echo "prozess: ${s}" fi fi done for s in "${!shutDownNoGoFiles[@]}" do if [ -e "${shutDownNoGoFiles[${s}]}" ] && echo "${prozesse}" | grep -q "^\S\+\s\+$(cat "${shutDownNoGoFiles[${s}]}")\s" then nochwarten=true if ! ${quiet}; then echo "datei: ${s}" fi fi done if ${nochwarten} then if ! ${quiet}; then echo "warten ..." fi i=10 continue else if ! ${quiet}; then echo "noch ${i} Sekunden" fi fi i=$[${i}-1] done beforeShutDownHook sudo /sbin/poweroff