Runs Fine In Perl :: Not As Cron Job

B

Bucker

Dear Folks,

I have a Perl application that just unzips a zip file once per day.

Perl Program is as follows: (daily.pl is program name)



system("cd /home/website/www/htdocs/batch/");
system("unzip -o /home/website/www/htdocs/batch/images.zip");


That is it..i also send a email to myself once this is completed but
that isn't the issue
because I receive the email every day.

Now..when I run this from the SSH prompt in the batch directory, (perl
daily.pl)
it runs like a champ..no problems no errors.

When I run this from a cron job. The unzip never occurs but I get the
email.

Here is the cron job

15 12 * * * cd /home/website/www/htdocs/batch; perl daily.pl


Now the above launches once a day because I receive the email in
daily.pl. My only issue is that
the unzip -o command in the daily.pl doesn't run. Any one have a
suggestion?


Regards,

Jim
 
J

John Bokma

Bucker said:
Dear Folks,

I have a Perl application that just unzips a zip file once per day.

Perl Program is as follows: (daily.pl is program name)



system("cd /home/website/www/htdocs/batch/");
system("unzip -o /home/website/www/htdocs/batch/images.zip");


That is it..i also send a email to myself once this is completed but
that isn't the issue
because I receive the email every day.

Now..when I run this from the SSH prompt in the batch directory, (perl
daily.pl)
it runs like a champ..no problems no errors.

When I run this from a cron job. The unzip never occurs but I get the
email.

Here is the cron job

15 12 * * * cd /home/website/www/htdocs/batch; perl daily.pl


Now the above launches once a day because I receive the email in
daily.pl. My only issue is that
the unzip -o command in the daily.pl doesn't run. Any one have a
suggestion?

Check the output of system, and mail yourself an error if it fails. I
guess that the path to unzip is not known. You could try:

which unzip

and provide the full path.

Yet I still recommend to check if system failed or not, and if it failed
to include this in the email.
 
P

Paul Lalli

Bucker said:
I have a Perl application that just unzips a zip file once per day.

Perl Program is as follows: (daily.pl is program name)
system("cd /home/website/www/htdocs/batch/");

This is a no-op. It does absolutley nothing worth mentioning. It
creates a shell process, changes directory, and exits the shell. That
change of directory has no impact on anything else. Please see also
"perldoc -q 'changed directory''"
system("unzip -o /home/website/www/htdocs/batch/images.zip");
That is it..i also send a email to myself once this is completed but
that isn't the issue
because I receive the email every day.

Now..when I run this from the SSH prompt in the batch directory, (perl
daily.pl)
it runs like a champ..no problems no errors.
When I run this from a cron job. The unzip never occurs but I get the
email.

Here is the cron job

15 12 * * * cd /home/website/www/htdocs/batch; perl daily.pl

Now the above launches once a day because I receive the email in
daily.pl. My only issue is that
the unzip -o command in the daily.pl doesn't run. Any one have a
suggestion?

You pretty clearly do not have a Perl problem. Your Perl program works
just fine. You have a cron problem. The most common cron problem is
that the cron script runs with different permissions and/or different
users and/or different environment variables than the logged-in user.
Have you checked any or all of these?

Have you checked the return value of the system() call from within your
Perl script?

Have you checked the value of $! to see if there was an operating
system error?

Paul Lalli
 
T

Tad McClellan

Paul Lalli said:
Bucker wrote:

This is a no-op. It does absolutley nothing worth mentioning.


So the OP should use Perl's builtin operator for changing
the current working directory:

perldoc -f chdir
 
P

Paul Lalli

Tad said:
So the OP should use Perl's builtin operator for changing
the current working directory:

perldoc -f chdir

Well, in the general case, yes. But in the OP's specific example,
there was no reason to change directory at all, as he specified the
full path to the file to unzip in the second system() call.

Paul Lalli
 
J

John W. Kennedy

Paul said:
Well, in the general case, yes. But in the OP's specific example,
there was no reason to change directory at all, as he specified the
full path to the file to unzip in the second system() call.

But not the path to output to.
 
A

anno4000

John W. Kennedy said:
But not the path to output to.

In fact I think Perl is more of a hindrance than a help with this
little cron job. We don't know the full story, but a series of shell
commands ought to do the job:

cd /x/y/z; unzip /hihi/haha/huhu.zip; echo "unzip cron job done"

Note that cron mails the output (of echo) to the user, so that takes
care of the email.

If this fails, the error message will also be mailed. Perl has hidden
the error.

Anno
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,006
Latest member
LauraSkx64

Latest Threads

Top