Home > Archive > PERL Beginners > February 2006 > tar command
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| Irfan J Sayed 2006-02-24, 6:57 pm |
| Hi All,
I need to execute unix tar command thru perl file
can somebody helps me out in this regard
Regards
Irfan Sayed
| |
|
|
| Chas Owens 2006-02-24, 6:57 pm |
| On 2/24/06, Irfan J Sayed <irfsayed@in.ibm.com> wrote:
> Hi All,
>
> I need to execute unix tar command thru perl file
> can somebody helps me out in this regard
>
> Regards
> Irfan Sayed
>
You might look at Tar
(http://search.cpan.org/~cdybed/Tar-0.04/Tar.pm), Archive::Tar
(http://search.cpan.org/~kane/Archiv.../Archive/Tar.pm),
and Archive::TarGzip
(http://search.cpan.org/~softdia/Arc...hive/TarGzip.p=
m)
if you need to access the tar files programmaticly. If you just want
to use the tar executable on your system then you can use system, the
backquote operator (AKA qx()), or a combination of fork and exec.
Assuming you do not need anything but a return value you can say
system("tar cfz foo.tgz /foo/*");
If you want to capture the stdout you can say
my @lines =3D `tar cvfz foo.tgz /foo/*`;
or
my @lines =3D qx(tar cvfz foo.tgz /foo/*);
If you need it to run concurrently with the Perl script you can say
$SIG{CHLD} =3D 'autoreap';
my $fork =3D fork();
die "could not fork:$!" unless defined $fork;
if ($fork) { #parent code
print "kicked off a child whose pid is $fork\n";
} else {
exec('tar', 'cvfz', '/foo/*');
}
I would suggest reading up on system, fork, exec, and the qx()
operator before doing anything.
perldoc -f system
perldoc -f fork
perldoc -f exec
perldoc perlop
or
http://perldoc.perl.org/functions/system.html
http://perldoc.perl.org/functions/fork.html
http://perldoc.perl.org/functions/exec.html
http://perldoc.perl.org/perlop.html
| |
| Irfan J Sayed 2006-02-24, 6:57 pm |
| Hi All,
Thanks for mail
I am using following script for backup of clearcase data. the problem is
that it executes upto the tar command but when it comes to the zip command
it simply hangs.
could u plz help me out
regards
irfan.
#!/usr/bin/perl -w
# This script takes the backup of vobs , make the tar and zip
# copy the zipped file in tape and keep it in a safe location.
# This is a daily backup procedure and needs to be started at midnight.
my ($CT,$vob_tag,$cc);
$CT = "/usr/atria/bin/cleartool";
$cc = "/opt/rational/clearcase/etc/clearcase";
@vob_list = (
"/vobs/second",
);
# Lock the every vob
foreach $vob_tag (@vob_list)
{
`$CT lock vob:$vob_tag`;
}
# Stop the clearcase to ensure no any file is open for writing
`$cc stop`;
# Taring the vob storage directory
system ("tar -cpvf /vobstg.tar /vobstg");
# Zip the tar file
system ("gzip vobstg.tar");
# start the clearacse
`$cc start`;
# unLock the every vob
foreach $vob_tag (@vob_list)
{
`$CT unlock vob:$vob_tag`;
}
Regards
Irfan Sayed
"Chas Owens" <chas.owens@gmail.com>
02/24/2006 09:22 PM
To
Irfan J Sayed/India/IBM@IBMIN
cc
beginners@perl.org
Subject
Re: tar command
On 2/24/06, Irfan J Sayed <irfsayed@in.ibm.com> wrote:
> Hi All,
>
> I need to execute unix tar command thru perl file
> can somebody helps me out in this regard
>
> Regards
> Irfan Sayed
>
You might look at Tar
(http://search.cpan.org/~cdybed/Tar-0.04/Tar.pm), Archive::Tar
(http://search.cpan.org/~kane/Archiv.../Archive/Tar.pm),
and Archive::TarGzip
(
http://search.cpan.org/~softdia/Arc...hive/TarGzip.pm
)
if you need to access the tar files programmaticly. If you just want
to use the tar executable on your system then you can use system, the
backquote operator (AKA qx()), or a combination of fork and exec.
Assuming you do not need anything but a return value you can say
system("tar cfz foo.tgz /foo/*");
If you want to capture the stdout you can say
my @lines = `tar cvfz foo.tgz /foo/*`;
or
my @lines = qx(tar cvfz foo.tgz /foo/*);
If you need it to run concurrently with the Perl script you can say
$SIG{CHLD} = 'autoreap';
my $fork = fork();
die "could not fork:$!" unless defined $fork;
if ($fork) { #parent code
print "kicked off a child whose pid is $fork\n";
} else {
exec('tar', 'cvfz', '/foo/*');
}
I would suggest reading up on system, fork, exec, and the qx()
operator before doing anything.
perldoc -f system
perldoc -f fork
perldoc -f exec
perldoc perlop
or
http://perldoc.perl.org/functions/system.html
http://perldoc.perl.org/functions/fork.html
http://perldoc.perl.org/functions/exec.html
http://perldoc.perl.org/perlop.html
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
<http://learn.perl.org/> <http://learn.perl.org/first-response>
| |
| Chas Owens 2006-02-24, 6:57 pm |
| On 2/24/06, Irfan J Sayed <irfsayed@in.ibm.com> wrote:
>
> Hi All,
>
> Thanks for mail
>
> I am using following script for backup of clearcase data. the problem is =
that it executes upto the tar command but when it comes to the zip command =
it simply hangs.
>
> could u plz help me out
>
> regards
> irfan.
>
snip
>
> # Taring the vob storage directory
>
> system ("tar -cpvf /vobstg.tar /vobstg");
>
> # Zip the tar file
>
> system ("gzip vobstg.tar");
>
snip
You refer to the tar file as /vobstg.tar in the tar command, but you
refer to it is vobstg.tar in the gzip command. This might be an issue
if your current working directory is not /. Otherwise, I don't see
any glaring errors.
| |
| Chas Owens 2006-02-24, 6:57 pm |
| On 2/24/06, Irfan J Sayed <irfsayed@in.ibm.com> wrote:
snip
> `$CT lock vob:$vob_tag`;
snip
> `$cc stop`;
snip
> `$cc start`;
snip
> `$CT unlock vob:$vob_tag`;
snip
I take back my last comment. You are using the backquotes
incorrectly. You should only use backquotes when you want to capture
the stdout of the program you are running. These should all be calls
to the system() function. Also you should be checking the return code
of the commands to make sure the worked.
if (system("$cc lock vob:$vob_tag")) {
print stderr "lock failed\n";
exit 1;
}
if (system("$cc stop") !=3D 0) {
print stderr "stop failed\n";
exit 2;
}
etc.
| |
| Chas Owens 2006-02-24, 6:57 pm |
| On 2/24/06, Irfan J Sayed <irfsayed@in.ibm.com> wrote:
>
> Hi All,
>
> Thanks for mail
>
> I am using following script for backup of clearcase data.
> the problem is that it executes upto the tar command but
> when it comes to the zip command it simply hangs.
>
> could u plz help me out
>
> regards
> irfan.
snip
You might also consider using ClearCase::CtCmd
(http://search.cpan.org/~ratl/CtCmd-1.04/CtCmd.pm) instead of calls to
the shell version of cleartool.
| |
| Irfan J Sayed 2006-02-24, 6:57 pm |
| Hi ,
I already tested with /vobstg.tar in the gzip command but still it's
hanging and i am executing this perl script from / partition only.
Main thing is that it's creating /vobstg.tar.gz file but not coming to
shell prompt or not executing next command
plz let me know any other option.
Regards
Irfan Sayed
"Chas Owens" <chas.owens@gmail.com>
02/24/2006 11:19 PM
To
Irfan J Sayed/India/IBM@IBMIN
cc
beginners@perl.org
Subject
Re: tar command
On 2/24/06, Irfan J Sayed <irfsayed@in.ibm.com> wrote:
>
> Hi All,
>
> Thanks for mail
>
> I am using following script for backup of clearcase data. the problem is
that it executes upto the tar command but when it comes to the zip command
it simply hangs.
>
> could u plz help me out
>
> regards
> irfan.
>
snip
>
> # Taring the vob storage directory
>
> system ("tar -cpvf /vobstg.tar /vobstg");
>
> # Zip the tar file
>
> system ("gzip vobstg.tar");
>
snip
You refer to the tar file as /vobstg.tar in the tar command, but you
refer to it is vobstg.tar in the gzip command. This might be an issue
if your current working directory is not /. Otherwise, I don't see
any glaring errors.
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
<http://learn.perl.org/> <http://learn.perl.org/first-response>
| |
| Tom Phoenix 2006-02-24, 6:57 pm |
| On 2/24/06, Irfan J Sayed <irfsayed@in.ibm.com> wrote:
> plz let me know any other option.
Have you tried the Perl debugger? See the perldebug manpage. Cheers!
--Tom Phoenix
Stonehenge Perl Training
| |
| Hans Meier 2006-02-24, 6:57 pm |
| Irfan J Sayed am Freitag, 24. Februar 2006 19.13:
> Hi ,
>
> I already tested with /vobstg.tar in the gzip command but still it's
> hanging and i am executing this perl script from / partition only.
>
> Main thing is that it's creating /vobstg.tar.gz file but not coming to
> shell prompt or not executing next command
>
> plz let me know any other option.
>
> Regards
> Irfan Sayed
[...]
What about using the additional -z option of tar, so you don't have to call
gzip separatly?
hth
Hans
| |
| Chas Owens 2006-02-24, 6:57 pm |
| On 2/24/06, Hans Meier (John Doe) <security.department@tele2.ch> wrote:
> Irfan J Sayed am Freitag, 24. Februar 2006 19.13:
> [...]
>
> What about using the additional -z option of tar, so you don't have to ca=
ll
> gzip separatly?
>
> hth
> Hans
That only works with the GNU version of tar. Although, you can
approximate it like this
tar cf - foo/* | gzip -c > foo.tar.gz
|
|
|
|
|