xomo has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I am doing SSH to a remote machine and running a shell script on it, What I want to do here is get the output of the shell script as shell script is executing meaning display the output on the machine which i m using without any delay. Right now, The script runs for 10mins and I have no output on my screen as what is happening in Shell Script. and then all the output comes suddenly after 10 mins, so I want to get the output of the Shell script running on the remote machine in which I m doing SSH without any delay so that USer which is Running Perl Script shall know that Shell script is running on the other end and doing Some Stuff. I did not mention that I am calling from perl script... using NET::SSH::PERL so its fairly simple the shell script which i want to run is 'snap.sh', which itself calls lots of stuff and gives the output/status of those one by one.. so I want the same thing to be seen on my server where I am running perl script as the shell script is running... Thanks. Xomo

Replies are listed 'Best First'.
Re: SSH OUTPUT WITHOUT ENDING OF COMMAND
by Anonyrnous Monk (Hermit) on Dec 08, 2010 at 18:09 UTC

    This is most likely a buffering issue.

    Try adding the -t option to the ssh call. This forces pseudo tty allocation, which in turn might cause the script on the other end to act line-buffered (as opposed to block-buffered, which is the default for non-interactive transfers).

    For example

    $ ssh -t localhost 'perl -E "say && sleep 1 for 1..10"'

    outputs 1..10 individually in one second intervals, while without the -t, you get all lines in one chunk when the 10 secs are over.

Re: SSH OUTPUT WITHOUT ENDING OF COMMAND
by How09 (Novice) on Dec 08, 2010 at 17:57 UTC
    Do you mean a "sh" or "bash" script? or a perl script.
    The "print" output should show in your ssh terminal window.
    If the script is fairly short why not post it?
      Ohh ...I did not mention that I am calling from perl script... using NET::SSH::PERL so its fairly simple the shell script which i want to run is 'snap.sh', which itself calls lots of stuff and gives the output/status of those one by one.. so I want the same thing to be seen on my server where I am running perl script as the shell script is running...
        If you are on a Linux/Unix system, you can use Net::OpenSSH:
        use Net::OpenSSH; my $ssh = Net::OpenSSH->new('foo@host'); $ssh->error and die "unable to connect: " . $ssh->error; my $pipe = $ssh->pipe_out("snap.sh"); while(<$pipe>) { print $_; }