anderson@optical.squibb.com (03/01/91)
When I run the following script from the csh prompt, it works fine. However, when I try to run it from cron it doesn't quite work as expected. Here's the crontab entry: 0,5,10,15,20,25,30,35,40,45,50,55 * * * * /usr/local/bin/perl /usr/local/bin/cron_ping Here's cron_ping: #!/usr/local/bin/perl # # Script to ping bozo to insure network # integrity. open(LOG, ">>/var/log/ping_log") || die "Can't open /var/log/ping_log"; chop($date = `date`); chop($result = `ping bozo 5`); # try for 5 secs to ping helix print LOG $date ," ", $result, "\n"; close(LOG); Here's what /var/log/ping_log looks like: Thu Feb 28 14:15:02 EST 1991 <- from cron Thu Feb 28 14:20:01 EST 1991 <- from cron Thu Feb 28 14:25:02 EST 1991 <- from cron Thu Feb 28 14:28:20 EST 1991 helix is alive <- by hand Thu Feb 28 14:28:38 EST 1991 helix is alive <- by hand Thu Feb 28 14:30:01 EST 1991 <- from cron Why does it work from the shell and not from cron? Jay Anderson anderson@optical.squibb.com
rbj@uunet.UU.NET (Root Boy Jim) (03/01/91)
In article <1991Feb28.193638.4002@uvaarpa.Virginia.EDU> anderson@optical.squibb.com writes: > >When I run the following script from the csh prompt, it works fine. >However, when I try to run it from cron it doesn't quite work as >expected. Here's the crontab entry: Stuff run from cron has almost no environment. Specifically, it has whatever cron's was. In certainly doesn't have your interactive one. Perhaps ping is not being found? -- [rbj@uunet 1] stty sane unknown mode: sane
rdm2@chaucer.uucp (25362-roe mcburnett(H053)m000) (03/01/91)
In article <1991Feb28.193638.4002@uvaarpa.Virginia.EDU> anderson@optical.squibb.com writes: > >When I run the following script from the csh prompt, it works fine. >However, when I try to run it from cron it doesn't quite work as >expected. >Here's cron_ping: ... >chop($result = `ping bozo 5`); # try for 5 secs to ping helix perhaps ---------^ ping is not in the path of the shell that cron spawned? >Why does it work from the shell and not from cron? > >Jay Anderson >anderson@optical.squibb.com Remember, cron uses sh (not ksh not csh) to run its commands. You might get better results by using the following: 0,5,10,15,20,25,30,35,40,45,50,55 * * * * ksh /usr/local/bin/perl /usr/local/bin/cron_ping -Roe McBurnett rdm2@chaucer.cc.bellcore.com
tchrist@convex.COM (Tom Christiansen) (03/01/91)
From the keyboard of rdm2@chaucer.UUCP (25362-roe mcburnett): :Remember, cron uses sh (not ksh not csh) to run its commands. You :might get better results by using the following: : :0,5,10,15,20,25,30,35,40,45,50,55 * * * * ksh /usr/local/bin/perl /usr/local/bin/cron_ping don't you mean: ksh -c '/usr/local/bin/perl /usr/local/bin/cron_ping' right? and you're just calling ksh to get a good path, right? might as well just put it in the cron_ping thing. BTW, *MY* cron lets me set its path. I think they all should. --tom -- "UNIX was not designed to stop you from doing stupid things, because that would also stop you from doing clever things." -- Doug Gwyn Tom Christiansen tchrist@convex.com convex!tchrist
jones@chpc.utexas.edu (Bill Jones) (03/01/91)
Cron scripts should ether set there path variable or use full paths. Bill Jones
rdm2@chaucer.uucp (25362-roe mcburnett(H053)m000) (03/01/91)
In article <1991Feb28.233630.21142@convex.com> tchrist@convex.COM (Tom Christiansen) writes: >From the keyboard of rdm2@chaucer.UUCP (25362-roe mcburnett): >:Remember, cron uses sh (not ksh not csh) to run its commands. You >:might get better results by using the following: >don't you mean: > ksh -c '/usr/local/bin/perl /usr/local/bin/cron_ping' >right? and you're just calling ksh to get a good path, right? >might as well just put it in the cron_ping thing. >BTW, *MY* cron lets me set its path. I think they all should. >--tom > Tom Christiansen tchrist@convex.com convex!tchrist Yes Tom, You are quite correct. I was using ksh to get a good path. On some of the systems I work on cron lets me set the path, or automatically uses my login .profile to setup one. This is why I just executed ksh, because the cron would know that *I* setup the crontab for me, and would use my .profile (which would setup the path just fine). I also think that they all should work this way. But unfortunately some of us are stuck with systems that are old and clunky. (on some systems that I support the only OS available is u*ix V.2 where the old cron stuff reigns supreme) Thanks for the clarification -Roe Roe D McBurnett III Bellcore (908)699-2273 rdm2@chaucer.cc.bellcore.com #insert <std.disclamer>
vixie@decwrl.dec.com (Paul A Vixie) (03/02/91)
>> BTW, *MY* cron lets me set its path. I think they all should.
Who cares? *MY* cron is in the public domain. Get it from a
comp.sources.unix archive site near you. Or get it from
gatekeeper.dec.com via prospero or anonftp. Or wait for 4.4BSD.
A cron that doesn't let you set its path, will not send you mail
if your commands generate output, and will not let each user have
their own crontab, is, well, it's not my version, whatever it is.
Cheers,
--
Paul Vixie
DEC Western Research Lab <vixie@wrl.dec.com>
Palo Alto, California ...!decwrl!vixie
tchrist@convex.COM (Tom Christiansen) (03/02/91)
From the keyboard of vixie@decwrl.dec.com (Paul A Vixie): :>> BTW, *MY* cron lets me set its path. I think they all should. : :Who cares? *MY* cron is in the public domain. Sorry, I should have said Convex's cron; I only hack at it until it stops annoying the dickens out of me. I didn't really write it. Paul's cron really is very nice; if your cron bugs you, get his. Even if yours doesn't annoy you, you might look at his. --tom -- "UNIX was not designed to stop you from doing stupid things, because that would also stop you from doing clever things." -- Doug Gwyn Tom Christiansen tchrist@convex.com convex!tchrist