Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Wait for string

by mrbullman (Initiate)
on Apr 27, 2015 at 21:11 UTC ( [id://1124924]=perlquestion: print w/replies, xml ) Need Help??

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

Wondering if there is a simple solution to the coding problem I have encountered. I ssh into a box and run a command to show some settings how ever if the amount of data returned is larger than the screen window you have to hit a key to continue. Is there a way to simulate hitting a key to continue printing the output to a file? ssh -l admin xxx.xxx.xxx.xxx admin's password: xxxxx

#!/bin/perl use Net::SSH::Expect; my $ssh = Net::SSH::Expect->new ( host => $host, password=> $pass, user => $user, raw_pty => 1, timeout => 3 ); my $login_output = $ssh->login(); if ($login_output !~ />/) { die "Login has failed. Login output was $login_output"; } my $who = $ssh->send("show config\n"); while ( defined ($line = $ssh->read_line()) ) { print $line . "\n"; } close $line; $ssh->close();

Replies are listed 'Best First'.
Re: Wait for string
by atcroft (Abbot) on Apr 28, 2015 at 01:00 UTC
    If you are using something such as Expect, Net::SSH::Expect, or similar, you may be able to make it look for the prompt ('--MORE----', in your example), and trigger sending a "\n" in response. Also, depending on the device you are connecting to, there may be a command (such as 'set term len 0', which I've seen on a particular type of device) you may be able to execute to prevent paging of the output. If not, you may look into changing your "pager" for the command to something that would not wait, such as "cat".

    Hope that helps.

Re: Wait for string
by Happy-the-monk (Canon) on Apr 28, 2015 at 05:18 UTC

    Is there a way to simulate hitting a key to continue printing the output to a file?

    Send "\n" to the terminal.

    However, it might be best to switch off the pager at your bash prompt:
    There may be a "pager" setting in the shell, or as this is bash, there may be a "$PAGER" environment variable to unset: export PAGER=""

    Unless, of course, the show out command has the pager built in. In that case, use the manual for that command to find out how to switch of paging.

    Cheers, Sören

    Créateur des bugs mobiles - let loose once, run everywhere.
    (hooked on the Perl Programming language)

Re: Wait for string
by Marshall (Canon) on Apr 28, 2015 at 00:52 UTC
    "more" is a standard Unix like gizmo that pauses the printout of a terminal so that you can read the screen and and hit space to see the next screen, etc.

    This is not a Perl question per sea, but the general idea is to use a command that produces a file and not a UI screen text output. This is a Unix question with bash UI.

    I hope that some Monk will help you with this problem. I am sure that many can do it.

    Cheers, Marshall

Re: Wait for string
by flexvault (Monsignor) on Apr 27, 2015 at 23:20 UTC

    Dear Monks,

    And the Perl question is?

    Regards...Ed

    "Well done is better than well said." - Benjamin Franklin

Re: Wait for string
by mrbullman (Initiate) on Apr 28, 2015 at 14:38 UTC
    The pager function worked for me. Thanks much for the help

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1124924]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2024-04-19 19:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found