Run / scripts / pkgacct using system (), exec () or backlinks

I have a small perl script that runs a command /scripts/pkgacctin cPanel with system(). The code looks like this:

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, backups of only the base data is stored by default cPanel roundcubeand horde. When I replace system()with exec"", the script works as expected, but exits as soon as it is executed exec, that is, subsequent instructions in the perl script are not executed. Using backticks shows the same behavior as system()- ie does not reserve all databases.

Can someone tell me what mistake I am making?

Alternatively, how can I get the rest of the instructions to execute after the command exec?

+4
source share
2 answers

Try using a system like this:

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

I found that the system works best when you break down the command and the parameters that it expects.

0
source

Try using IPC :: Run ( https://metacpan.org/pod/IPC::Run ). Your code will look something like this:

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/'];
0
source

All Articles