Script for sending HD's to Standby if PC is Offline - Help

Status
Not open for further replies.

Grinchy

Explorer
Joined
Aug 5, 2017
Messages
78
Hello,

some time ago i found this Script (Sorry, don't know anymore who made it) for turning off FreeNAS if all PCs in this IP Range are offline.

Code:
#!/bin/bash

HOST1=192.168.2.33 #IP des ersten PC
HOST2=192.168.2.35 #IP des zweiten PC
ip_range=192.168.2. #Netzadresse des eigenen Netzwerkes ohne den Hostanteil
ip=40 #checke Netz ab IP-Adresse 40
_exit () {
case $1 in
  1) echo "Kein Shutdown - Mindestens einer der PCs ist eingeschaltet" ;;
  2) echo "Kein PC online - Shutdown" ; shutdown -p now ;;
esac
exit $1;
}
# Checken ob PC's an sind
if [ `ping -c 1 -i 1 $HOST1 | grep -wc 100.0%` -eq 0 ] || [ `ping -c 1 -i 1 $HOST2 | grep -wc 100.0%` -eq 0 ] ;
then _exit 1; # abbrechen, ein PC läuft
# Wenn kein PC an ist, gehe zu Checken ob PC's im IP-Bereich an sind
else
# Checken ob PC's im IP-Bereich an sind
  while [ $ip -le 45 ] #checke Netz bis Hostanteil 45
do
  ping -c 1 -i 1 $ip_range$ip #ping mit der zusammengesetzten IP-Adresse aus den o.a. Variablen "ip" und "i"
  if [ `ping -c 1 -i 1 $ip_range$ip | grep -wc 100.0%` -eq 0 ] #sobald einer der Hosts auf den ping antwortet, nicht herunterfahren
then _exit 1 #beenden mit exit 1 (kein shutdown)
fi
 ip=$(( $ip+1 )) #erhöhe Hostanteil immer um 1
done
_exit 2 # hat kein PC geantwortet, shutdown
fi


Now i thought about modding this Script, so that it won't turn off Freenas, but put the Harddrives into sleep. This way you can set fixed times when the Harddrives are supposed to sleep. In my Case that would be at night and though the Working Day. Also they won't sleep if there's a PC running and are back to use in Seconds.
Using the normal x-min to sleep timer won't work in my case, cause I'm using an Fan Script that uses smartctl all 3 minutes, which resets the sleep timer. Also it will go to sleep to many times.

I'm quite new to this Stuff, so I wanted to ask wether there's a way to call all Harddrives?

The Point in this Script would be "echo "Kein PC online - Shutdown" ; shutdown -p now ;;". If i now replace "shutdown -p now" with "camcontrol standby /dev/adaX" it should work the same way, but put the Disk into Standby.

But this way you can only put 1 Harddrive into Standby. Something like /dev/ada[0-7] won't work, but is there some command like this to call all harddrives at once?

Would be great if someone could help me here.
 

zemun2

Explorer
Joined
Mar 15, 2017
Messages
72
I think you can change that when you click storage then view disks.

Screenshot 2018-01-23 11.23.52.png
 

Grinchy

Explorer
Joined
Aug 5, 2017
Messages
78
Yes, but that won't work if you are using an Fan Script. Fan Scripts use Smartctl to get the HD temps and normally refresh between 3-5 minutes. But Smartctl will reset the Standby timer of the Harddrive every time you use Smartcrl. So it can't go to sleep.

That's why I thought of a way, to at least put the Disks to sleep at Night and during the working day. Also I think that would be a nice way to save energy without putting to much Stress on the drives.

Even when doing this without script and just using a Cronjob at Night with "camcontrol standby /dev/adaX" you would have to make one for every Drive. So knowing some way to call all drives would be really nice.
 
Status
Not open for further replies.
Top