C
C
Cat_CooLeR2014-03-26 14:27:05
Perl
Cat_CooLeR, 2014-03-26 14:27:05

Perl + Cron - why is the file not saved?

Hello!
There is a Perl script with this piece:

$msg .= "path: $fname \n";
        unlink($fname);
        unless (-d $_[2]) {mkdir 'in/'.$_[2], 0755;}
        open(OUT,"> $fname") or $msg .= "$fname not save! \n";
        local $/ = undef;
        print OUT $content,"\n";
        close(OUT);

$fname is the path to the file, $msg is a message that is then put into the database
And this script is run by cron every 20 minutes, here is from the /etc/crontab
*/20 * * * * root /usr/bin/perl *путь к файлу*
file: " *filename* not save " and does not overwrite the file. What can be done?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
pcdesign, 2014-03-26
@Cat_CooLeR

Here are a few options on how to win this:
1) You can add these lines to the script, somewhere on top.

BEGIN {
    use Cwd 'chdir';    # Запуск скрипта из крона
    use File::Basename;
    chdir dirname $0;    # Меняем путь
}

2) Or do it first in the crown:
3) In your script, specify the full path to the file.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question