Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I tried putting script like this:-
#!/bin/sh
date >> /home/date
halt

It works when the network cable removed manually and i have inserted the script in /etc/network/if-down.d. Its not working when the swtich is off. Can any one please tell me how to write script for this?

share|improve this question
    
out of curiosity, why should a server halt when the network drops? –  warren Nov 9 '09 at 9:56
    
our client are facing a lot of power fluctuations, if the ups drained out in middle of night, the servers will shutdown abruptly so better to write a script that's the reason. –  Caterpillar Nov 9 '09 at 11:07
4  
That's your solution? You know, UPSes can tell the server that they're running out of power and it's time to shut down gracefully... –  womble Nov 9 '09 at 11:14
    
i know that, But that stupid ups provider has not given any cable to it... :-( otherwise i could've done like that..Please tell me how to write script. –  Caterpillar Nov 9 '09 at 12:35
    
I think for business purposes it might benefit you to do it right and spend whatever money is required to get the cable. What type of UPS is it? –  oneodd1 Nov 9 '09 at 19:30
add comment

3 Answers

This is obviously a rather ugly hack. But you could put a script into crontab that periodically checks for network & shuts down the system if it's no longer there. Sort of a Dead man's Switch.

share|improve this answer
    
you're right, that is an ugly hack. +1, i like it. :) –  quack quixote Nov 9 '09 at 13:21
add comment

Have you tried putting your script in /etc/network/if-post-down.d/?

share|improve this answer
    
Yeah! I tried it, But did'nt work.. :( –  Caterpillar Nov 9 '09 at 11:08
    
I don't see how this could work. AFAIK, /etc/network/if-post-down.d/ is called if the network connection is shut down locally (by calling the approriate shutdown programs/scripts). It is not invoked if the network just dies for reasons outside the local system. –  sleske Dec 7 '11 at 8:29
add comment

is the script chmodded as executable?

chmod +x /etc/network/if-down.d/*scriptname*
share|improve this answer
    
Yeah!! without that script will not run.. :) i have done.. –  Caterpillar Nov 9 '09 at 12:36
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.