Link to home
Create AccountLog in
Avatar of Shamsul Kamal
Shamsul Kamal

asked on

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

Avatar of woolmilkporc
Flag of Germany image

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
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.
Avatar of Shamsul Kamal
Shamsul Kamal



/bin/cat \>  helps .