perl in crontab

N

news.hinet.net

This test can work when i run it anywhere.
But the chdir seem does not work when i set it in crontab??
==============================================
#!/usr/bin/perl

chdir("/usr/local/admin/dir");
system("tar zcvf test.tgz *");
 
S

Sam Holden

This test can work when i run it anywhere.
But the chdir seem does not work when i set it in crontab??
==============================================
#!/usr/bin/perl

chdir("/usr/local/admin/dir");
system("tar zcvf test.tgz *");

So test the return value and report the failure including the
error message:

chdir("/usr/local/admin/dir") or die "chdir failed: $!";
system("tar zcvf test.tgz *")==0 or die "system failed: $!";
 
S

Sherm Pendley

news.hinet.net said:
This test can work when i run it anywhere.
But the chdir seem does not work when i set it in crontab??

Like Sam said - check for errors and print error messages.

Also, look at the man pages for cron and crontab. Cron jobs run under a
limited environment - most notably, the PATH variable is not likely the
same as it is when you log into a shell.

sherm--
 
S

Shawn Corey

Hi,

Two possible reasons. 1) Permissions: the crontab is running under a
different user that cannot access the files. 2) No profile: cron does
not run the user's .profile (or .cshrc and .login for csh) when it runs.
Try using the full path for tar, system( "/usr/bin/tar ...
 
I

Ian Wilson

news.hinet.net said:
This test can work when i run it anywhere.
But the chdir seem does not work when i set it in crontab??
==============================================
#!/usr/bin/perl

chdir("/usr/local/admin/dir");
system("tar zcvf test.tgz *");
Also man tar, many tar implementations have a command line option for
setting the initial directory for the operation.
 

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

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top