diff options
| author | Horus3 | 2014-10-08 02:16:43 +0200 |
|---|---|---|
| committer | Horus3 | 2014-10-08 02:16:43 +0200 |
| commit | 23ef2763f0b0645871d8294a1e2aa9fe5660b66b (patch) | |
| tree | 2fa24cf804ebbecb1515c3c3df2883d82dc7cbf2 | |
| parent | a74b3c31f95f72cf2aac7e74b77d319eb6bf34c6 (diff) | |
| download | dotfiles-23ef2763f0b0645871d8294a1e2aa9fe5660b66b.tar.gz | |
added autoshut.sh
| -rwxr-xr-x | bin/autoshut.sh | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/bin/autoshut.sh b/bin/autoshut.sh new file mode 100755 index 0000000..8c677ee --- /dev/null +++ b/bin/autoshut.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +function idle { + prog="$1" + while pgrep "$prog" >/dev/null; do + sleep 3 + done + shutdown -hP now +} + +prog="irssi" +daemon=false + +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 + +while [ $# -gt 0 ]; do + if [ "$1" == "-p" ]; then + shift + prog="$1" + shift + elif [ "$1" == "-d" ]; then + daemon=true + shift + else + echo "Unsupported argument '$1'" 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 + exit 1 +fi + +if [ $daemon == true ]; then + idle "$prog" >/dev/null 2>&1 & + disown +else + idle "$prog" >/dev/null 2>&1 +fi |
