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'm writing a silly little script to email people when a (Debian Lenny) server boots. Right now I've set it up as an init.d script using update-rc.d, but then I realized I could have just used cron jobs instead. Is it better to use cron jobs for something like this, or init.d?

I haven't actually tested whether the script runs at boot time but it should work. Haven't tried rebooting yet, but the underlying problem is that we randomly had the server reboot once and just shut down/power down randomly another time, so we're wondering whether it's power failures or something else. This would at least let us know when the server reboots.

share|improve this question

3 Answers 3

up vote 4 down vote accepted

Since this sounds like a run-and-be-done script I would say that /etc/rc.local or cron (time: @reboot) is definitely the way to go.

On the other hand, anything which will stay daemonized should definitely has its own init script. If nothing else, to make sure it shuts down properly.

share|improve this answer
    
Ah, so making it an init script is kind of overkill? I thought it might be, but I wasn't sure. I think I'll go the /etc/rc.local route rather than mess with cron, since it's really just a one line script. –  Ibrahim Dec 9 '09 at 22:06
    
Oh, does /etc/rc.local get run on shutdown or reboot (runlevels 0 and 6 if I understand correctly)? –  Ibrahim Dec 9 '09 at 22:13
1  
No, rc.local is start-only. If something needs to be shut down, it needs its own /etc/rc[0-6].d entries, or upstart (which is replacing sysv init to allow parallel booting). On Debian, /etc/rc.local is run from /etc/init.d/rc.local, which only has start entries. –  Peter Cordes Dec 10 '09 at 0:57

/etc/rc.local gets executed on each boot, after all the other init scripts run. That would be another easy-to-implement option.

share|improve this answer
    
Ah, that seems to be the simplest way to do it without leaving a lot of cruft everywhere. –  Ibrahim Dec 9 '09 at 22:12

Cron is a time based system. There are a lot of ways to do it. In lenny, you can use a script in /etc/rc.local. This file will be run at end of process, after all network startup that is needed to send mails.

share|improve this answer
    
Well, the email is sent to a local user, but that's probably a valid concern. –  Ibrahim Dec 9 '09 at 22:04
1  
An extension of cron is the ability to specify a time as "@reboot". Being an extension means, of course, the some versions don't support it. –  Dennis Williamson Dec 9 '09 at 22:52

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.