summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2016-04-09 21:55:10 +0200
committerErich Eckner <git@eckner.net>2016-04-09 21:55:10 +0200
commit4eb26ade00c26cee4a112fa8e4113b1699357d99 (patch)
tree47b71bf8982ea54b15a9e1c8d19e523f7d0bd08c
downloadshutdownasap-4eb26ade00c26cee4a112fa8e4113b1699357d99.tar.xz
initialer Commit
-rwxr-xr-xshutdownasap68
1 files changed, 68 insertions, 0 deletions
diff --git a/shutdownasap b/shutdownasap
new file mode 100755
index 0000000..e921b84
--- /dev/null
+++ b/shutdownasap
@@ -0,0 +1,68 @@
+#!/bin/bash
+
+[ -e /tmp/shutdownasap.pid ] && ps aux | grep -q "^[^ ]* *$(cat /tmp/shutdownasap.pid) " && exit
+
+echo $$ > /tmp/shutdownasap.pid
+
+i=1
+while [ ${i} -gt 0 ]
+do
+ sleep 1
+ prozesse="$(ps aux | grep -v grep)"
+
+ nochwarten=false
+
+ if ls -1A /home/shutdown/.warteauf | grep -q "."
+ then
+ nochwarten=true
+ echo ".warteauf: "
+ ls -1A /home/shutdown/.warteauf
+ fi
+
+ if users | grep -q "."
+ then
+ nochwarten=true
+ echo -n "users: "
+ users
+ fi
+
+ for synActFile in /sys/block/md*/md/sync_action
+ do
+ if [ -r "${synActFile}" ] && ! grep -q "^idle\$" "${synActFile}"
+ then
+ nlochWarten=true
+ echo -n "raid ${synActFile}: "
+ cat "${synActFile}"
+ fi
+ done
+
+ for s in $(cat /etc/shutdownnogo)
+ do
+ [ "${s}" == "backup" ] && t="${s}" || t="${s}\(\$\|\s\)"
+ if echo "${prozesse}" | grep -q "\(\s\|/\)${t}\(\$\|\s\)"
+ then
+ nochwarten=true
+ echo "prozess: ${s}"
+ fi
+ done
+
+ if ${nochwarten}
+ then
+ echo "warten ..."
+ i=10
+ continue
+ else
+ echo "noch ${i} Sekunden"
+ fi
+ i=$[${i}-1]
+done
+
+if ping 192.168.0.15 -c1 &> /dev/null
+then
+ if ssh shutdown@192.168.0.15 ls -1 /home/shutdown/.warteauf | grep -q "^192\.168\.0\.18\$"
+ then
+ ssh shutdown@192.168.0.15 rm /home/shutdown/.warteauf/192.168.0.18
+ fi
+fi
+
+sudo /sbin/poweroff