summaryrefslogtreecommitdiff
path: root/shutdownasap
blob: e921b84a8c51cd8f24f8c5235c6fc15c4a333bbe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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