Auto network restart or reboot after network loss

So i know there are and have been some scenarios where people’s My cloud drives, lose nework connectivity and they need to power cycle it.

In hopes to try to have somewhat of an automated remedy for that, i came across a script that might help other.

I’ve implemented it on my drive and seems to work in cases where i intentionally unplug the nerwork cable. Not sure when the drive goes in that limbo state for some people if the script would work or not.

Anyways, save the file as with a “.sh” extension at any path on your my cloud. Then setup a cron job to call the script. I’m calling it every 3 hours, so as not to wake up the drive too often.

Im also storing output from the script in case it triggers are network restart or a reboot. you can choose to exclude the echo lines if you dont want that.

Script: 

#!/bin/bash
test_host=`netstat -nr | grep "UG" | awk '{ print $2}' | xargs ping -q -w 1 -c 1 | grep "received" | awk '{ print $4 }'`
if ["$test_host" == "0"] || [-z "$test_host"] ;
then
echo "service networking restart" >> /shares/data/Drivers/scripts/no_ip_reboot_output.txt
/etc/init.d/networking restart
sleep 60

test_host=`netstat -nr | grep "UG" | awk '{ print $2}' | xargs ping -q -w 1 -c 1 | grep "received" | awk '{ print $4 }'`
   if ["$test_host" == "0"] || [-z "$test_host"] ;
then
echo "Rebooting" >> /shares/data/Drivers/scripts/no_ip_reboot_output.txt 
shutdown -r now
   fi
fi

Cronjob:

0 */3 * * * root /shares/data/Drivers/scripts/no_ip_reboot.sh
1 Like

Hi alirz1, thanks for sharing this information. For other users that try this, note that this could void the warranty of your device if not applied correctly. 

Jubei04,

Is there a list of things we’re allowed to do under the SSH interface provided with the product?

Or maybe a list of things we’re not allowed to do?

I do wonder about the legal status of these vague ‘warranty warnings’… [IANAL]

If the product worked out of the box as it should, we wouldn’t need to muck about with Linux command line and scripts via SSH…

1 Like

Technically any modification done via ssh voids warranty. But so does rooting a smartphone, or a custom firware on your router etc…

But you know how it is…original software can always be restored back.

cpt_paranoia wrote:

Jubei04,

 

Is there a list of things we’re allowed to do under the SSH interface provided with the product?

 

Or maybe a list of things we’re not allowed to do?

 

I do wonder about the legal status of these vague ‘warranty warnings’… [IANAL]

 

If the product worked out of the box as it should, we wouldn’t need to muck about with Linux command line and scripts via SSH…

Kudos … :wink:

So today i encountered that infamous “network loss” issue where the drive looks to be up and running, solid blue led, normal network green leds on the back, yet the drive cannot be accessed in any manner and also cannot be pinged.

(I have static Ip assigenment FROM the router based on device MAC)

Once i found the drive in that state today, i left it like that until the next scheduled cronjob for my above mentioned script to see if it reboots its self. guess what IT DID NOT.

So there are  ONLY two possibilites left now.

1- The OS on the WD drive crashed/kernel panicked such that it was not even able to run a cron job

OR

2- My script works on the fact that if the drive cannot ping its gateway (my router) thats when it triggers the network restart and then eventually a reboot. So with that said, possibly the drive could ping the router and hence it never restarted?

If that would be the case, then why i cannot ping drive from my computer when the drive is in this state!