Hey,
das geht wohl, indem du ein Code-Device einbaust und dann ein entsprechendes Script ausführst das sich am NAS anmeldet und den Shutdown-Befehl ausführt.
Ich hab im Grunde das selbe gemacht, nur damals noch ohne Raspberry - mit nem Router mit OpenWRT und nem Script direkt am NAS:
1: Am Router (OpenWRT) läuft ein Script das dem NAS ein WOL schickt, sobald ein Client (IP) online ist.
2: Ich hab am NAS ein Script laufen, dass alle x Minuten prüft, ob die "wichtigen" Clients noch da sind, oder ob noch Traffic am NAS is. Wenn nicht, schicke ich es in den DeepStandby.
Router - das Programm wird einmal gestartet nachdem der Router hochgefahren ist - über /etc/rc.local. Am Router ist das Paket "etherwake" installiert.
Code: Select all
#!/bin/ash
# define important hosts
hosts="192.x.x.x 192.x.x.x 192.x.x.x 10.x.x.x"
NAS=192.x.x.x # QNAP NAS
NASMAC=00:xx:xx:xx:xx
# start loop
while true
do
sleeptime=1
# check if NAS is online
ping -q -W 1 -c 1 $NAS > /dev/null
if [ $? == 0 ]; then # NAS is already online
sleeptime=30
else
# check if host is online
for host in $hosts ; do
if ping -q -W 1 -c 1 $host > /dev/null; then
# wake-up NAS
logger -t NAS "Host online: $host - Waking up NAS (WOL) (IP: $NAS)"
#/usr/bin/wol -i 192.x.x.255 -p 9 $NASMAC # Wake up NAS
etherwake $NASMAC # Wake up NAS
sleeptime=30
break
fi
done
fi
# wait before we start again
sleep $sleeptime
done
Das Script liegt auf nem USB-Stick (Willi) der nicht verschlüsselt ist. Das Script wird über crontab alle 30 Minuten gestartet.
Code: Select all
#!/bin/sh
# define important hosts
hosts="192.x.x.x 192.x.x.x 10.x.x.x" # array of important hosts
# define counter-settings
crontabcycle=30 # crontab cycle time - 30 minutes
min_on_time=60 # minimum online time for NAS -> eg. it should be running 1 hour after clients were shutdown
# define packet-thresholds
rx_thresh=1000
tx_thresh=1000
# define local variables
b_netTraffic=0 # boolean indicator for noticeable network traffic -> 0 = no traffic | 1 = traffic
b_hostOnline=0 # boolean indicator for an online host
# check network traffic (packets) to be sure no one is using the NAS
# get current values
rx=`/sbin/ifconfig eth0 | grep 'RX packets' | cut -d : -f 2 | cut -d " " -f 1`
tx=`/sbin/ifconfig eth0 | grep 'TX packets' | cut -d : -f 2 | cut -d " " -f 1`
# read old values from file
rx_old=$(</share/WILLI/scripts/AutoSleep/rx_packets)
tx_old=$(</share/WILLI/scripts/AutoSleep/tx_packets)
# write new values to file
echo $rx > /share/WILLI/scripts/AutoSleep/rx_packets
echo $tx > /share/WILLI/scripts/AutoSleep/tx_packets
#compare new to old values
if [ $((rx-rx_old)) -le $rx_thresh ] && [ $((tx-tx_old)) -le $tx_thresh ]; then
#/sbin/write_log "No noticeable network traffic.." 4
b_netTraffic=0 # no noticeable network traffic
else
#/sbin/write_log "A lot of traffic on the network.." 4
b_netTraffic=1 # someone uses the NAS...
fi
# ping hosts - check if they are online
for host in $hosts ; do
if ping -q -c 1 $host > /dev/null; then
b_hostOnline=1 # one host is online
#/sbin/write_log "at least one host is online" 4
break
fi
done
if [ $b_hostOnline == 0 ] && [ $b_netTraffic == 0 ]; then # all clients are offline and there was no noticeable network traffic
/sbin/write_log "clients offline - checking if NAS should go to sleep.." 4
# check the time the clients are already offline
counter=$(</share/WILLI/scripts/AutoSleep/client-offline-counter) # read counter-value from file
# reset counter, put NAS to sleep-mode, if min_on_time is exeeded
if [ $counter == $((min_on_time/crontabcycle-1)) ]; then
/sbin/write_log "NAS is entering sleep-mode due to inactive clients" 4 # write message to system-log (4 = info)
counter=0
echo $counter > /share/WILLI/scripts/AutoSleep/client-offline-counter
sleep 5
sh /etc/init.d/pw_sleep.sh
else
#/sbin/write_log "sleep-counter incremented" 4
counter=$((counter+1)) # increment counter
echo $counter >/share/WILLI/scripts/AutoSleep/client-offline-counter
fi
else
# reset counter
counter=0
echo $counter > /share/WILLI/scripts/AutoSleep/client-offline-counter
#/sbin/write_log "hosts online - sleep-counter reset" 4
fi
Eventuell kannst du das Script am NAS ebenfalls laufen lassen und im Z-Way über Presence und ein Mini-Script ein WOL ans NAS schicken.