[wplug] perl / cron problem

Jonathan Billings billings at negate.org
Fri Oct 21 15:51:59 EDT 2005


Mike S wrote:
> Hello,
> 
> I'm wondering if there is anybody who can help me out with a little cron
> problem I'm having.
> 
> I have a script, erBackup.pl, which basically tar's and scp's some files
> to a remote host.  Note:  I use an encrypted id_rsa file, and have
> ssh-agent running.
> 
> When I run it from bash, it works like a charm.  When I run it from cron,
> I get emails from cron with the output of the program (sans std::out or
> std::err from programs like tar and scp).  The script appears to run to
> the end.

Just to make sure, are you sure the cron job is running with the SSH agent?

> I use the following sub to call the commands I use (mostly tar and scp):
> 
> sub run (@)
> {
>     my @args = shift;
>     system (@args) == 0 or die "\nSystem error: @args\nError: $@";
> }

This seems like a rather pointless function.  Why don't you replace any 
run(...) functions with "system(...) == 0 or die ...".  Also, "my @args 
= shift" only puts the first argument in @args, so you're only running 
system with the first parameter passed to run().  You're probably 
running the run(...) function with only one parameter, so you haven't 
encountered any problems yet.

> The program takes about three minutes to run when it works, but when cron
> calls it, it hustles through in no time flat.  (Though some print commands
> at the end of the script do appear in the output.)

You could have it store and print the exit status of the system() 
command, to see what the return value of it was.


> And as if that weren't a perplexing enough problem for a Friday at 3:00pm,
> there's one more twist.  Make sure you're sitting down.
> 
> I'm using cygwin.
> 
> Any thoughts?

The fact that you're using 'cygwin' will probably add all sorts of 
strangeness.  How does cygwin run cron?  does it do the right thing to 
pass on ssh agent env variables?

-- 
Jonathan S. Billings <billings at negate.org>


More information about the wplug mailing list