How to run a script to copy a file from GUNZIP and TAR in PERL ?


I would like to request an assistant.

It seems that when running the following bash file , the copy function running fine :

root@svr27 [/]# tar Oxzf /backup/cpbackup/daily/server2.tar.gz server2/homedir.tar | tar -Oxf - ./public_html/index.html | cat > /home/server2/public_html/index.html

But if i converted it into perl script, it seem the file copied is blank ...

Appreciates if anybody can spot where is the mistake.

FYI, i have confirm all variable is running fine.

Thank you.

sub copyfileinbackup {
print "$header<br>\n";
$backuptype = $FORM{'backuptype'};
$copyfolder = $FORM{'copyfolder'};
if (!$copyfolder) {
$slash = ""
else {
$slash = "/"
$userfile = $FORM{'userfile'};
$user = $FORM{'user'};
print "\n<br><br><b>This function is to copy <b>$userfile </b> file from /backup/cpbackup/$backuptype/$user.tar.gz  to /home/$user/public_html/$copyfolder folder.....<br><br></b>\n\n";
if (!$user) {
print "<font color=red><b>You did not provide the username to copy the file ....</font></b><br><br>\n";
else {
print "<br><br><b>The <b>$userfile </b>  file will be copied as follows : <font color=red><br><br>\n";

print "<b>Copy <b>$userfile </b> file from /backup/cpbackup/$backuptype/$user.tar.gz to /home/$user/public_html/$copyfolder folder ..... </b>\n";
system("cd /backup/cpbackup/$backuptype ");
system("/bin/tar -Oxzf /backup/cpbackup/$backuptype/$user.tar.gz $user/homedir.tar|/bin/tar -Oxf - ./public_html/$copyfolder$slash$userfile|/bin/cat > /home/$user/public_html/$copyfolder$slash$userfile");
system("chown $user:$user /home/$user/public_html/$copyfolder$slash$userfile");
print "</b><br><br><br>\n";
print "<font Color=green><b>Done</b></font><br><br>\n";
print "</b><br><br><br>COMPLETED<br>\n";

Open in new window

Shamsul KamalJunior TechAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hi again,

I'm by no means a Perl expert - but could it be that you'll have to escape the ">" character in the system call, like

"... |/bin/cat \> /home/$user/public_html/... ..."


Another possibility could be making tar change to the appropriate target directory, so we won't need "cat" at all:

" ... |/bin/tar -C /home/$user/public_html/$copyfolder -Oxf - ./public_html/$copyfolder$slash$userfile");


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Are you sure tar lives in /bin on that system?
Other than that, I don't see anything obvious but if you could post the HTML output so I can see what it's echoing for the values of the form fields, I could compare that to see if you should be getting the output you expect.
Shamsul KamalJunior TechAuthor Commented:

/bin/cat \>  helps .
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Scripting Languages

From novice to tech pro — start learning today.