Hi there stranger! :)
I have searched the web for different solutions to my problem, but nothing really works.... :/
I have 2 bat-fieles, which are working fine, but actually I will only be able to use one of them.
What do I want to do:
I want my NAS to shutdown, when some devices are not connected to the network. The WOL part is working fine actually.
These are my codes:
shutdown.bat
wol.bat
Both work fine. WOL will work from the Autostart menu or I will use the tasker as soon I enter my
appartement... so no worries about that.
The problem is, that I cannot use the shutdown command. What If my Girlfriend is working on some important document and I'm to lazy to call her or shout trough the appartement to ask her if she does... Why can't my NAS check if her PC is still running.... or the Rasberry is running, or anything that is important and uses the NAS.
I have fond a really cool script which is apparently not that cool, cause it does not work... :/ Or I'm just missing something...
You cant find the code and instructions here:
http://martin.leyrer.priv.at/y2014/m08/Waking_up_and_shutting_down_FreeNAS_on_demand.html
or code only; auto_shutdown.sh
pcs.txt (just for completeness + MAC adresses are fake)
And this is how I have implemented it as a cronjob:
with "Redirect Stdout" i get the following message after running the cronjob manually:
relevant lines are generated at 20:58.
If anyone out there could help me, I would be so thankful!
cheers, maxbenn! :)
I have searched the web for different solutions to my problem, but nothing really works.... :/
I have 2 bat-fieles, which are working fine, but actually I will only be able to use one of them.
What do I want to do:
I want my NAS to shutdown, when some devices are not connected to the network. The WOL part is working fine actually.
These are my codes:
shutdown.bat
Code:
start cmd.exe /c plink -ssh -pw password root@192.168.146.35 shutdown -p now
wol.bat
Code:
start cmd.exe /c wol.exe 00aa11bb22cc
Both work fine. WOL will work from the Autostart menu or I will use the tasker as soon I enter my
appartement... so no worries about that.
The problem is, that I cannot use the shutdown command. What If my Girlfriend is working on some important document and I'm to lazy to call her or shout trough the appartement to ask her if she does... Why can't my NAS check if her PC is still running.... or the Rasberry is running, or anything that is important and uses the NAS.
I have fond a really cool script which is apparently not that cool, cause it does not work... :/ Or I'm just missing something...
You cant find the code and instructions here:
http://martin.leyrer.priv.at/y2014/m08/Waking_up_and_shutting_down_FreeNAS_on_demand.html
or code only; auto_shutdown.sh
Code:
#!/bin/bash # REPLACE WITH YOUR SUBNET START SUBNET=192.168.146. # REPLACE WITH YOUR SUBNET END SHUTDOWN=true # Fill ARP cache export COUNTER=1 while [ $COUNTER -lt 255 ] do ping -c 1 -t 1 $SUBNET$COUNTER 1>/dev/null & COUNTER=$(( $COUNTER + 1 )) done #wait for pings to finish sleep 3 while IFS= read -r MAC <&3; do # skip empty lines in file if [ -z "$MAC" ]; then continue fi # Let's see, if we find a IP for the current MAC VAR=`arp -a | grep $MAC` if [ -z "$VAR" ]; then : else # We have an IP for the MAC, so the PC might still be on. Check with ping IP=`echo "$VAR" | cut -d ' ' -f1` PING=`ping -c 1 -q $IP | grep -c '1 packets received'` if [ $PING -eq 0 ]; then printf "%s\tPC down\n" $MAC : else echo "$MAC PC online" # Abort shutdown SHUTDOWN=false # One PC running is enough to keep the server running break fi fi done 3< "./pcs.txt" if [ "$SHUTDOWN" = true ] ; then echo "Shutdown this server" /sbin/shutdown -p now else echo "Do nothing, keep server running" fi
pcs.txt (just for completeness + MAC adresses are fake)
Code:
00:11:22:33:44:55:66 AA:BB:CC:DD:EE:FF
And this is how I have implemented it as a cronjob:


with "Redirect Stdout" i get the following message after running the cronjob manually:

relevant lines are generated at 20:58.
If anyone out there could help me, I would be so thankful!
cheers, maxbenn! :)
Last edited: