Perl script with `command` in cron not right

Michael Fowler wolfm at pobox.alaska.net
Thu May 11 19:49:00 CDT 2000


On Thu, May 11, 2000 at 04:08:57PM -0800, K Creason wrote:
> I have a Perl script I scheduled in cron.
> BUT (of course there's a but to this)
> this line:
> $r=`cat /home/911/alert.msg |smbclient -M $mac[$c] -R wins -U "911 Alert"`;

Just as a note, this is one of those notorious Useless Uses of Cat.

    $r = `smbclient -M $mac[$c] -R wins -U "911 Alert" < /home/911/alert.msg`


> will do every thing up to the included pipe command. The script works
> perfect from the command line, cron just doesn't do that part.

If it works on the command line and not when executed by cron it's usually
an environment issue; you're making some assumption about the environment,
or using some environmental variable, that doesn't exist within cron.

Are there any environmental variables smbclient relies on to work properly
in this situation?  My smbclient man page mentions USER and PASSWD.  USER
shouldn't be required because you're specifying a username, but PASSWD may
be.

Your Perl script may also rely on its environment in some way, perhaps for
setting $mac[$c].


> I know cron does some of it's won redirections, so is it the multiple
> redirect*s that go on in a cron job?

Whatever cron may or may not do with respect to redirections shouldn't
affect fork/exec within your program.



> I've tried the cron job scheduled like these two ways, following my HP-UX
> experience:
> * * * * * /home/911/ptel.pl >/home/911/ptel.log
> and
> * * * * *  /home/911/ptel.pl
> 
> It's never logged a thing to the cron piped log, so maybe that HP function
> isn't included in linux.

Every version of cron I've seen uses /bin/sh to execute the command.  Any
shell metacharacters would, therefore, be recognized.  Both of the above
lines should work as you intended.


> I've altered the perl line to include full path to the smbclient binary,
> no fix the problem.
> The cat function works, the alert.msg file is always updated.

You may want to replace your cat-to-smbclient line with:

    $r = `cat /home/911/alert.msg`

and print $r out, to verify there are messages there at the point the cron
job is run.


That's about all I can think of at the moment.


Michael
--
Administrator                      www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--
=================================================
Mailing list info:  If at any time you wish to (un|re)subscribe to
the list send the request to majordomo at hfb.pm.org.  All requests
should be in the body, and look like such
                  subscribe anchorage-pm-list
                  unsubscribe anchorage-pm-list



More information about the Anchorage-pm mailing list