t-rex has asked for the wisdom of the Perl Monks concerning the following question:

i am transferring a pl script and a tar folder on a remote server through openssh package (scp_put)and want this pl script to untar the folder on the remote

i am not sure how to achieve this , but i dont want to do it using system() please suggest some method

Replies are listed 'Best First'.
Re: untaring at remote location
by Corion (Patriarch) on Jun 15, 2016 at 07:26 UTC

    There are many approaches to unpacking or inspecting a tar archive. The most common approach for treating tar files in Perl would be Archive::Tar. The module has some restrictions, as it wants to keep the whole tar archive in memory. See Tar or Archive for other suggestions.

      please see below comments @Corion , need help with that

Re: untaring at remote location
by GotToBTru (Prior) on Jun 15, 2016 at 13:01 UTC

    Look into Net::OpenSSH or its brethren.

    But God demonstrates His own love toward us, in that while we were yet sinners, Christ died for us. Romans 5:8 (NASB)

Re: untaring at remote location
by salva (Canon) on Jun 15, 2016 at 07:57 UTC
    i dont want to do it using system

    why?

Re: untaring at remote location
by Anonymous Monk on Jun 15, 2016 at 07:19 UTC
    um, log into the remote machine using ssh , run the program
Re: untaring at remote location
by t-rex (Scribe) on Jun 15, 2016 at 08:16 UTC

    ok guys i got it : now i am facing a problem : my aim is to create a socket program with concurrent server so what i do is from my client i try connecting to a port initially and when it fails i just transfer a tar file with a perl script to server and run a server program , now i am stuck in system() from which i invoke the script on the server because this server will keep listening till the end of time (machine is off) and my system gets hung, is there any way i can get out of this system() even though the server should keep running, the test function is similar to system but is more robust 9 from open ssh package)

    my $ssh = Net::OpenSSH->new ( $hostmachine, user =>$username, password + => $password); $ssh->scp_put($sourcedir,$sourcedir2,$remote_path) or die "scp failed \n" . $ssh->error; my $rc = $ssh->test('perl sabkuch.pl'); #check if test function returned or not if ($rc == 1){ print "test was ok , server established \n"; } else { print "return from test = $rc \n"; } exit;

    the file sabkuch.pl is as follows

    #!/usr/bin/perl use strict; use warnings; + system('tar -xvf test.tar'); exec('cd utpsm_run_automation && perl utpsm_lts_server.pl'); exit;

    please help

      Have you considered launching your program on the remote end and having it detach from its SSH session? Most likely a double-fork or simply launching it via nohup should put your script in the background, detached from the session that started it.

      Also, the "Perl" script you've shown is basically just a shell script. If you really want to use Perl, I would replace cd by the chdir function and the invocation of utpsm_lts_server.pl to either the do function or just start that program directly from the calling SSH script.

      Also note that exec never returns.

        thanks for the info , i dont know how to use nohup , perl is also new for me hence i wasnt aware of the chdir and do , now i was trying to use fork: sabkuch.pl forks a child which will run this server , the code is something like this, but that too is not getting me desired result

        1 #!/usr/bin/perl 2 3 use strict; 4 use warnings; 5 6 system('tar -xvf test.tar'); 7 8 my $child_pid = fork; 9 10 if (!defined $child_pid){ 11 print "couldn't fork \n"; 12 } 13 14 else { 15 print "in child , now executing \n"; 16 exec('cd utpsm_run_automation && perl utpsm_lts_server.pl') 17 or die "can't run server.pl in sabkuch child \n"; 18 } 19 20 exit;

        could you please help me with this ?

      Corion did help, more than 45 minutes before you posted this node, here.