4

I have a small perl script which runs the /scripts/pkgacct command in cPanel using system(). The code looks like so;

print  "\n/scripts/pkgacct --skiphomedir --nocompress $acc_name /my_backup\n\n";
system("/scripts/pkgacct --skiphomedir --nocompress $acc_name /my_backup");
my $bk_path = "/my_backup/cpmove-$acc_name.tar";
system("tar -xvf $bk_path -C /my_backup/");

When I run the script, only cPanel's default roundcube and horde databases are backed up. When I replace system() with exec"", the script runs as expected but terminates as soon as exec is executed, i.e the subsequent statements in the perl script aren't executed. Using backticks shows the same behaviour as system() - i.e doesn't backup all the databases.

Could someone tell me what mistake I am making?

Alternately, how can I get the remaining statements to execute after the exec command?

4

2 回答 2

0

尝试使用 IPC::Run ( https://metacpan.org/pod/IPC::Run )。您的代码将类似于:

use IPC::Run qw(run);

print  "\n/scripts/pkgacct --skiphomedir --nocompress $acc_name /my_backup\n\n";
run ['/scripts/pkgacct', '--skiphomedir', '--nocompress', $acc_name];
my $bk_path = "/my_backup/cpmove-$acc_name.tar";
run ['tar','-xvf',$bk_path,'-C','/my_backup/'];
于 2015-04-06T20:31:16.920 回答
0

尝试像这样使用系统:

system('/scripts/pkgacct', '--skiphomedir', '--nocompress', $acc_name, '/my_backup');

我发现当您像预期的那样分解命令和参数时,系统工作得最好。

于 2013-10-22T17:41:45.297 回答