summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHorus32014-10-10 12:48:18 +0200
committerHorus32014-10-10 12:48:18 +0200
commit13357bb5830ab40164bd2b4b1efcde431a68e5fd (patch)
tree4bba32a52e56376155db2679f4504b3e83e0a3a0
parent23ef2763f0b0645871d8294a1e2aa9fe5660b66b (diff)
downloaddotfiles-13357bb5830ab40164bd2b4b1efcde431a68e5fd.tar.gz
autoshut.sh printhelp()
-rwxr-xr-xbin/autoshut.sh27
1 files changed, 20 insertions, 7 deletions
diff --git a/bin/autoshut.sh b/bin/autoshut.sh
index 8c677ee..8be2e56 100755
--- a/bin/autoshut.sh
+++ b/bin/autoshut.sh
@@ -2,18 +2,23 @@
function idle {
prog="$1"
- while pgrep "$prog" >/dev/null; do
+ while pgrep "$prog" >/dev/null 2>&1; do
sleep 3
done
shutdown -hP now
}
-prog="irssi"
-daemon=false
+usage="Usage: $0 [-d] [-p PROCESS]"
+function printhelp {
+ echo "A small shellscript which shutdowns your computer when a specific process ends"
+ echo $usage
+ echo "-d daemonize into the background"
+ echo "-p PROCESS commit the process name for which we are waiting to finish"
+ exit
+}
-if [ $UID != 0 ]; then
- read -p "We aren't root! Are you sure you have the proper permissions? If yes, press any key to continue or CTRL+C to abort. " null
-fi
+prog=""
+daemon=false
while [ $# -gt 0 ]; do
if [ "$1" == "-p" ]; then
@@ -23,18 +28,26 @@ while [ $# -gt 0 ]; do
elif [ "$1" == "-d" ]; then
daemon=true
shift
+ elif [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
+ printhelp
else
- echo "Unsupported argument '$1'" 1>&2
+ echo "Unsupported argument '$1'. Try '-h' for more help." 1>&2
exit 1
fi
done
if [ -z "$prog" ] || [ "$prog" == "" ]; then
echo "I'm confused. Which programm shall I monitor? Tell me, master!" 1>&2
+ echo $usage
exit 1
fi
+if [ $UID != 0 ]; then
+ read -p "We aren't root! Are you sure you have the proper permissions? If yes, press any key to continue or CTRL+C to abort. " null
+fi
+
if [ $daemon == true ]; then
+ echo "Daemonizing..."
idle "$prog" >/dev/null 2>&1 &
disown
else