#!/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 reboot=false while [ $# -gt 0 ]; do case "$1" in '-q') quiet=true ;; '-r') reboot=true ;; *) >&2 echo 'usage: shutdownasap [-q] [-r]' exit 1 ;; esac shift done beforeWatchHook i=1 while [ ${i} -gt 0 ] || ! additionalWatchHookSlow do if [ ${i} -eq 0 ] then i=1 fi 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 ! additionalWatchHookFast then nochwarten=true if ! ${quiet}; then echo "additionalWatchHookFast" fi fi 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 if ${reboot}; then sudo /sbin/reboot else sudo /sbin/poweroff fi