Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable pagination on the command line

I am trying to write a script using the python module pexpect that will connect to a server and execute commands like you are typing at the command line.

So for example, you can have something like:

child = pexpect.spawn('/usr/bin/ssh [email protected]')

child.sendLine('ls -al')

or whatever command you want to send. It will act like you are typing in a terminal.

In my script, I am trying to run a command using the sendLine() API that essentially dumps out a bunch of info to the command line. But there is a pagination that requires there to be another command where you have to press a key to continue to get to the next command.

So for example:

[Some info]

--------------- To continue, press any key. To quit, press 'q'. ---------------

[Some more info]

Is there a way that I can turn pagination off or a command I can send before I try to dump the info to the command line to turn it off?

like image 684
Nicholas Treu Avatar asked Dec 05 '25 05:12

Nicholas Treu


1 Answers

In Linux: You can use redirection to skip the pager(more or less). If it is important to display the output on screen, the output can be redirected to tee.

For example in man ls; ls, the man command expects the user to press q for termination and then ls is executed. To execute both the commands simultaneously without user intervention, it can be done as man ls | tee; ls. If displaying the output is not mandatory, it can be redirected to /dev/null as well.

For additional help, please specify the exact command that you are trying to execute on the remote server.

In Python: When using pexpect, the user activity can be automated if the intermediate output is known in advance. You can use expect function to wait for a particular output and then take necessary action(for example using sendLine).

like image 178
Pratap Avatar answered Dec 07 '25 19:12

Pratap



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!