Shutdown on idle + Hosts offline, WOL

Status
Not open for further replies.

maxbenn

Dabbler
Joined
Sep 3, 2015
Messages
14
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
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:
fnp01.jpg
fnp02.jpg


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

relevant lines are generated at 20:58.

If anyone out there could help me, I would be so thankful!

cheers, maxbenn! :)
 
Last edited:
Joined
Jan 9, 2015
Messages
430
I have a few questions. How many times a day would the server be shutting down and starting back up? How will this affect the drives in the long run? Assuming you are doing this to save power, how much will it really save? Do you really what to wait on the server to boot up and come online?
 

pirateghost

Unintelligible Geek
Joined
Feb 29, 2012
Messages
4,219
The savings in electricity are negligible at best when you factor in the amount of power the power on spin up state takes.
 

maxbenn

Dabbler
Joined
Sep 3, 2015
Messages
14
The OS is on a USB Stick... My drives are powered down after 30 min idle anyway and one is set to 5 min. So booting the system shoudn't vost that much I gues... But I will check it and come back with some numbers! :)
How much I will really safe? Hmmm... An least at night it will power down. During the day when nobody will be home. I can send a WOL package when getting near home via Tasker/Llama so I won't have to wait till the system boots up, but already running, when I'm entering the door.
Anyway... I will measure the difference and post it here as soon as I get them. :)

But is there anyone how could possibly help with my initial problem?

Cheers, maxbenn :)

Gesendet von meinem A0001 mit Tapatalk
 

maxbenn

Dabbler
Joined
Sep 3, 2015
Messages
14
https://docs.google.com/spreadsheets/d/1XJCHfI4ny0RsRoez1QLOtqFXfal9os2Ci7gB--x2OCc/edit?usp=sharing
Only 2 drives spin up... Actually the really old ones. I'll try to boot it with all drives unpluged and check for the system Power Consumtion itself without the WD drives with intelipower or whatever it is called...

EDIT: Power Consumtion w/o Disks added.

EDIT2:
I'm paying 0.23 €/kWh.
My NAS ist consuming approx. 50 W avarage. So 1 kWh/50 W=20 h

Scenario 1: It runs 24/7
1 year = 8760 h | (8760 h*1 kWh/20 h* 0.23 €/kWh) / 12 months = 100.74 / 12 months = 8.40 / month

Scenario 2: It runs 10 hrs/day
365 days * 10 h = 3650 h | (3650 h*1 kWh/20 h* 0.23 €/kWh) / 12 months = 41.98 / 12 months = 3.50 / month

I think it is worth it...

cheers, maxbenn
 
Last edited:

maxbenn

Dabbler
Joined
Sep 3, 2015
Messages
14
Overworking my drives? If it turns off, when I'm leaving the house or going to bed, would I be "overworking" my drives? I don't think so. And I can give you my Bank account details and you can send me 5€ á month, since it is silly for you?! ;)

Actually, I would love to get back to the topic... Anybody, who can help me with this?

Thanks, maxbenn

Gesendet von meinem A0001 mit Tapatalk
 

Bidule0hm

Server Electronics Sorcerer
Joined
Aug 5, 2013
Messages
3,710
The thing is that drives love constancy, especially regarding temperature and spinning-up.

What @pirateghost says is that by doing that you will save $5 of electricity but you'll lose more money than that by replacing the drives more often.

We usually fix the limit at one cycle per day, if you spin-up/down more than that it's probably a bad idea.
 

maxbenn

Dabbler
Joined
Sep 3, 2015
Messages
14
So you are saying that drives love consistency... Well, mine are consistently spinning up and down... ;) nah, just kiddin... :D
Well... So even leaving for 8 hrs or sleeping is bad? I mean, they will run as long the NAS is up. It would be cool if it just turns of while I at work or sleeping.... Still a bad idea?

Cheers, maxbenn :)

Gesendet von meinem A0001 mit Tapatalk
 

Bidule0hm

Server Electronics Sorcerer
Joined
Aug 5, 2013
Messages
3,710
If you just power it on, let it run, then shut it down once per day it'll be ok. What is bad is to spin-down the drives each time you don't use them many times per day ;)
 

BigDave

FreeNAS Enthusiast
Joined
Oct 6, 2013
Messages
2,479
Scenario 1: It runs 24/7
1 year = 8760 h | (8760 h*1 kWh/20 h* 0.23 €/kWh) / 12 months = 100.74 / 12 months = 8.40 / month

Scenario 2: It runs 10 hrs/day
365 days * 10 h = 3650 h | (3650 h*1 kWh/20 h* 0.23 €/kWh) / 12 months = 41.98 / 12 months = 3.50 / month

I think it is worth it...
What everyone is trying to explain is that hard disks (enterprise/NAS grade) have been proven to last longer if they
DO NOT spin down. Based on your scenario above, you save on power costs over a five year period, but due
to the nature of hard disks operating under those conditions, they will need to be replaced (more frequently) at a
much greater cost than the power savings, i.e. over a five year period.
 

pirateghost

Unintelligible Geek
Joined
Feb 29, 2012
Messages
4,219
A NAS is intended to be on all the time. If you want to shut it down several times a day, you don't need a NAS but just a PC.

I can't believe that after the cost of proper hardware, one could complain about $5/month...
 

diedrichg

Wizard
Joined
Dec 4, 2012
Messages
1,319
Don't shoot the messenger; I'm just spitballing here...

But what if you shut down ONLY from midnight to 08:00? That's 2,920 hours per year that X number of drives will not be running, or exactly 4 months (1/3 of the year), or that's 11% of a WD Red warranty period of 26,280 hours for one year.

Now let's say that even 1 drive failed during the year if we ran it 24/7, at $155USD for a 4TB WD Red that's $50.96 for the same 4 months to replace the drive.

Is it worth it to save 11% of the warranty or is it worth it to run 24/7?
 

BigDave

FreeNAS Enthusiast
Joined
Oct 6, 2013
Messages
2,479
Is it worth it to save 11% of the warranty or is it worth it to run 24/7?
I'm not quite fully awake this morning so please don't shoot me either...
afaik, while I'm sleeping, devices in the house are backing up to the FreeNAS volume AND the kids/grandkids demand access
until the early morning hours for God only knows what. I spend (within reason) whatever the cost to keep them from tearing my
body from limb to limb :eek: :p
 

Bidule0hm

Server Electronics Sorcerer
Joined
Aug 5, 2013
Messages
3,710
Yep, I agree night time is good for house keeping things like SMART tests, scrubs, backups, ... :)
 

maxbenn

Dabbler
Joined
Sep 3, 2015
Messages
14
Ok... Well but still... I would love to have such a script and let it only run during night hrs (from 10pm till 5am) and check every hour. It wouldn't be that bad...? I would switch it back on when I'm back home in the afternoon... I don't have kids and not going to have any soon... So wouldn't it be responsible? No backups are made at night... And having high-end hardware, doesn't mean than you can make a monthly gift to your electricity provider. I can accept it, that economically it is better not to run it 24/7 and not spinning down, but even still when the NAS is not in use for such a long time? Somebody said, that I could also use PC for accessing my data... Well no, cause I have SSDs only in there and a waterloop... The reason I build the NAS, was that the only thing making still noises, were the HDDs. So they needed to get out of the system... Now I have the raspberries and other PC's at home, so the NAS is actually a must-have right now... And it is 60 € a year. So, is it worth the 60 euros a year for spinning them down once per day and spinning up again? The HDDs which died right now were bought 2008... And there are still 2 in there from that time. The others are WD Reds.

Don't get me wrong... I don't want to be rude, but this is how my father raised me. Maybe others thought, that I am one of there spoiled kids but I never was... He was rich and after having my drivers licence I asked if I can get a Car and he replied: "Sure! Find a Job and earn it!" And this is why I think that even 60 € / year is a lot of money. Sure, it wouldn't hurt to loose it but it wouldn't hurt to keep it as well... So from the economical point of view.... Is it still worth it with the last scenario... I think yes. After 3 years I would save 180€ and for that I could buy a new one.

Cheers, maxbenn!

Gesendet von meinem A0001 mit Tapatalk
 

maxbenn

Dabbler
Joined
Sep 3, 2015
Messages
14
After re-reading the post... I did a wrong calculation. I have 4 Drives in my NAS... I will spend 170€ / drive... So actually I need to safe more than 4x170€ cause during the shutdown all drives are spinning down and not only one. So it would be 680/60 is 11.something.... After 11 years I could swap all HDDs for the cost of saving the electricity... Maybe you guys are god damn right! :)

Cheers, maxbenn....

Gesendet von meinem A0001 mit Tapatalk
 

Bidule0hm

Server Electronics Sorcerer
Joined
Aug 5, 2013
Messages
3,710
As I already said, for only once a day I'd probably do it if it's down for more than a few hours, something like 10 hours for example ;)
 
Status
Not open for further replies.
Top