Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   perl in crontab (http://www.velocityreviews.com/forums/t888076-perl-in-crontab.html)

news.hinet.net 09-17-2004 02:28 AM

perl in crontab
 
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 *");



Sam Holden 09-17-2004 02:58 AM

Re: perl in crontab
 
On Fri, 17 Sep 2004 10:28:42 +0800,
news.hinet.net <sonet.all@msa.hinet.net> wrote:
> 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: $!";


--
Sam Holden

Sherm Pendley 09-17-2004 11:32 AM

Re: perl in crontab
 
news.hinet.net wrote:

> 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--

--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org

Shawn Corey 09-17-2004 12:01 PM

Re: perl in crontab
 
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 ...

news.hinet.net wrote:

> 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 *");
>
>



Ian Wilson 09-20-2004 10:06 PM

OT Re: perl in crontab
 
news.hinet.net wrote:

> 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.


All times are GMT. The time now is 05:13 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.