Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Using Cron to Run Script

by sifukurt (Hermit)
on Dec 28, 2001 at 19:59 UTC ( [id://134891]=note: print w/replies, xml ) Need Help??


in reply to Using Cron to Run Script

I ran into a similar problem once with a script that was making backups of files. It ran correctly from the command line, but didn't run correctly from cron. To be honest, I never really did figure out why it didn't work in the cron, but I ended up with a work-around that solved the problem. I don't have a Linux machine at hand, so I haven't tested this to make sure that it will work in your situation, but it worked for me with my backup script.
$logdir = "/whatdir/"; opendir(LOGDIR, $logdir) or die "Can't open $logdir: $!\n"; chdir $logdir; foreach $file ( grep {-f && (-M > 5)} readdir(LOGDIR) ) { unlink $file; } closedir(LOGDIR);
As I said, I haven't been able to test that to confirm that it will work in your situation, but the situation I had was very similar, and it worked for me.

HTH
___________________
Kurt

Replies are listed 'Best First'.
Re: Re: Using Cron to Run Script
by wileykt (Acolyte) on Dec 28, 2001 at 22:34 UTC
    Thanks,
    For some reason chdir works even though before I was telling it where to find the file to delete in the unlink.
    Keith
Re (tilly) 2: Using Cron to Run Script
by tilly (Archbishop) on Jan 05, 2002 at 19:06 UTC
    The reason for the problem is that the filetests are going against the file names directly. So if you are listing files in directory /foo while you are in /bar, you are looking at whether /bar/baz is an old file when what you really wanted to know is whether /foo/baz is an old file.

    You have posted one workaround. The other is:

    my $logdir = "/whatdir/"; opendir(LOGDIR, $logdir) or die "Can't open '$logdir': $!\n"; foreach my $file ( grep {-f && (-M > 5)} map "$logdir$_", readdir(LOGDIR) ) { unlink $file; } closedir(LOGDIR);

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://134891]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-04-20 02:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found