ich habe mir ein kleines Shutdown Script geschraubt, das im Netzwerk schaut ob noch Rechner online sind und nachdem alle
offline sind fährt der Server runter.
Meine Idee war das ganze per Cron zu steuern. Doch leider fährt der Server nicht runter und ich komme hier nicht weiter.
In der Crontab habe ich folgenden Eintrag gemacht:
Code: Alles auswählen
root@wega:~# crontab -l
# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h dom mon dow command
0,15,30,45 * * * * /usr/bin/wegadown.sh
Das Script sieht so aus:
Code: Alles auswählen
#!/bin/bash
CLIENTS=`cat /root/wegadown/ips.dat`
a=0
for i in $CLIENTS
do
ping -c 2 $i
if test $? -eq 0
then
a=1
echo "$i ist erreichbar!"
fi
done
if test $a -ne 1
then
echo "Der Server wird heruntergefahren..."
shutdown -h now
exit
fi
In der /root/wegadown/ips.dat stehen die IP Adressen drin.
Und wenn ich in die Syslog schaue, sehe ich auch das es ausgeführt wird:
Code: Alles auswählen
Jan 19 21:48:01 wega /USR/SBIN/CRON[4238]: (root) CMD (/usr/bin/wegadown.sh)
Code: Alles auswählen
root@wega:~# /usr/bin/wegadown.sh
PING 192.168.0.2 (192.168.0.2) 56(84) bytes of data.
64 bytes from 192.168.0.2: icmp_req=1 ttl=64 time=0.288 ms
64 bytes from 192.168.0.2: icmp_req=2 ttl=64 time=0.237 ms
--- 192.168.0.2 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 999ms
rtt min/avg/max/mdev = 0.237/0.262/0.288/0.030 ms
192.168.0.2 ist erreichbar!
PING 192.168.0.4 (192.168.0.4) 56(84) bytes of data.
From 192.168.0.1 icmp_seq=1 Destination Host Unreachable
From 192.168.0.1 icmp_seq=2 Destination Host Unreachable
--- 192.168.0.4 ping statistics ---
2 packets transmitted, 0 received, +2 errors, 100% packet loss, time 1006ms
pipe 2
PING 192.168.0.3 (192.168.0.3) 56(84) bytes of data.
From 192.168.0.1 icmp_seq=1 Destination Host Unreachable
From 192.168.0.1 icmp_seq=2 Destination Host Unreachable
--- 192.168.0.3 ping statistics ---
2 packets transmitted, 0 received, +2 errors, 100% packet loss, time 1006ms
pipe 2
Gruß
Christoph