문제

i am using a perl script for unzipping a zip file by crontab. The script is working properly if i execute it manually. but whenever i set it in cron the script does not work any more. i have tested cron setting other script files are working from cron only this zip extracting script is not working .

Script is as follows :

#!/usr/bin/perl
use IO::Uncompress::Unzip qw(unzip $UnzipError);
$dir = '/root/perl';
open (han2, "ls -l $dir/*.zip |awk '{print \$9}'|");
@array1 = <han2>;
chomp(@array1);
for ($i=0;$i<=$#array1;$i++) {

$zipfile = $array1[$i];
$u = new IO::Uncompress::Unzip $zipfile
    or die "Cannot open $zipfile: $UnzipError";

die "Zipfile has no members"
    if ! defined $u->getHeaderInfo;

for ( $status = 1; $status > 0; $status = $u->nextStream) {
     $name = $u->getHeaderInfo->{Name};
    warn "Processing member $name\n" ;

    if ($name =~ /\/$/) {
        mkdir $name;
    }
    else {
        unzip $zipfile => $name, Name => $name
            or die "unzip failed: $UnzipError\n";
    }
}

}

Crontab setting :

34 14 * * * /root/perl/./unzip.pl > /dev/null 2>&1

Please help me to do this task by cronjob

도움이 되었습니까?

해결책

When cron executes your script, the current directoy probably won't /root/perl. Try chdir($dir) after you set $dir, or use full pathnames where required:

$u = new IO::Uncompress::Unzip "$dir/$zipfile"
or die "Cannot open $zipfile: $UnzipError";

mkdir "$dir/$name";

unzip "$dir/$zipfile" => "$dir/$name" ...

Changing to the correct directory is probably easier.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top