[英]Zip file is not extracting by crontab
i am using a perl script for unzipping a zip file by crontab. 我正在使用Perl脚本通过crontab解压缩zip文件。 The script is working properly if i execute it manually. 如果我手动执行脚本,脚本将正常工作。 but whenever i set it in cron the script does not work any more. 但是,每当我在cron中设置脚本时,该脚本便无法正常工作。 i have tested cron setting other script files are working from cron only this zip extracting script is not working . 我已经测试了cron设置,其他脚本文件无法从cron正常工作,只有此zip提取脚本无法正常工作。
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 : Crontab设定:
34 14 * * * /root/perl/./unzip.pl > /dev/null 2>&1
Please help me to do this task by cronjob 请帮助我通过cronjob来完成此任务
When cron executes your script, the current directoy probably won't /root/perl
. 当cron执行脚本时,当前目录可能不会/root/perl
。 Try chdir($dir)
after you set $dir
, or use full pathnames where required: 设置$dir
,尝试chdir($dir)
,或在需要时使用完整路径名:
$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 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.