[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[cobalt-users] cron question - script doesn't write to log file when run by crond [Raq4]
- Subject: [cobalt-users] cron question - script doesn't write to log file when run by crond [Raq4]
- From: Chris Bell <chris@xxxxxxxxxxxxxxx>
- Date: Tue Jan 21 05:58:01 2003
- List-id: Mailing list for users to share thoughts on Sun Cobalt products. <cobalt-users.list.cobalt.com>
I have a cron script (perl) that checks whether the network interface is
still up and restarts it if there's a problem. I've modified the script so
that it writes a line to a log file either saying that everything was OK or
that it had to restart the network interface.
When I run my cron script from the command line (as root) it writes to my
logfile, but when crond runs it (from the root user crontab) it doesn't...
The routine that sends me an email seems to work however.
I made sure the logfile was world writable because I figured it might use
the cron user's privileges to do so...
I also had tried 1>dev/null and 2>dev/null in my crontab and tried removing
it but as I expected this didn't make a difference. The relevant line in my
root crontab looks like this:
0,5,10,15,20,25,30,35,40,45,50,55 * * * *
/home/sites/home/users/admin/System/NetRestart/netrestart.pl
The relevant part of my script is below... any ideas why this wouldn't
work? The script seems to function fine otherwise, it's already had to take
action once, it's just that when I get cron to run it it won't write to the
log file!
Thanks
cb
--
# if network unavailable, restart
open (LOG, ">>logs/netrestart.log");
flock(LOG,2);
seek(LOG,0,2);
unless ($ok) {
system ("/etc/rc.d/init.d/network", "stop");
system ("/etc/rc.d/init.d/network", "start");
print LOG "$date|$time|Network restarted\n";
open(MAIL,"|$mailprog");
print MAIL "To: $recipient\n";
print MAIL "Subject: NetRestart has restarted the server\n\n";
print MAIL "The server was restarted at $date, $time\n\n";
close (MAIL);
} else {
print LOG "$date|$time|Network check succeeded\n";
}
close (LOG);