{{ :supportukraine.gif|}} ====== Synology: Ping dependent DSM auto shutdown via script with Tux ====== {{en:tux.png |Hey, my name is "Tux"!}} **Did you ever wonder how you can shutdown your //Synology// NAS automatically when its clients don't need it anymore?** \\ \\ Hey, my name is "Tux" and this tutorial will show you how you can set up a pinging script on your //Synology// NAS which shuts down your //Synology// NAS itself whenever specific NAS clients are not reachable anymore over the network within a specific amount of time. ---- \\ ===== First thoughts ===== This tutorial is not for everyone! It is basically for people who want their NAS being turned off to save power when it is not in use by its client(s). Mostly this takes place when the NAS is configured as a media server only. \\ ===== Start of tutorial ===== Create the following auto-shutdown script: $ vi /root/pingCheckAutoShutdown.sh Add the following content (Important: If you copy-paste the following content, make sure you replace the according whitespaces with tabulators. Alternatively type in the script code manually to avoid formatting issues as Linux command line is very(!) sensitive!). \\ The following example is pinging three (3) NAS clients. Only if all of the three clients are not reachable anymore via ping over network for example an mount of 900 seconds the NAS will shutdown itself. The ''delaytime'' variable value decides the interval of the script being repeated after it has reached its end. Feel free to adjust the script according to your requirements! #!/bin/sh # host01="" host02="" host03="" sleeptime= #for example "900" delaytime= #for example "60" # while true; do ping -c 1 "$host01" > /dev/null host01Result="$?" #echo "Result01: $host01Result" ping -c 1 "$host02" > /dev/null host02Result="$?" #echo "Result02: $host02Result" ping -c 1 "$host03" > /dev/null host03Result="$?" #echo "Result03: $host03Result" if [ "$host01Result" == 1 ] && [ "$host02Result" == 1 ] && [ "$host03Result" == 1 ]; then sleep "$sleeptime" ping -c 1 "$host01" > /dev/null host01Result="$?" #echo "Result001: $host01Result" ping -c 1 "$host02" > /dev/null host02Result="$?" #echo "Result002: $host02Result" ping -c 1 "$host03" > /dev/null host03Result="$?" #echo "Result003: $host03Result" if [ "$host01Result" == 1 ] && [ "$host02Result" == 1 ] && [ "$host03Result" == 1 ]; then poweroff fi fi sleep "$delaytime" done; Save the file and quit the editor. \\ \\ Now make the script executable: $ chmod +x /root/pingCheckAutoShutdown.sh Now quit the //SSH// session. \\ \\ Now configure the script to run on every NAS system start via //Synology//'s //Task Scheduler// (//Triggered Task//). \\ ===== End of tutorial ===== \\ \\ Appreciate my work? \\ [[https://www.buymeacoffee.com/fabioU|Buy me a coffee]] {{:buymeacoffee.png|}} or [[https://www.paypal.com/donate/?hosted_button_id=TH8Q3NTJCAJBA|PayPal]] {{:paypal.png|}} \\ \\ **Source(s):** \\ [[https://www.synology-wiki.de/index.php/Automatisches_Herunterfahren_wenn_kein_Ping_m%C3%B6glich|Synology-Wiki.de: Automatisches Herunterfahren wenn kein Ping möglich]] {{htmlmetatags>metatag-robots=()}}