question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Suppress banner/MOTD of run output

See original GitHub issue

Hi,

The run command output includes the banner set in the device and there is no way to suppress it. Code:

conn = await asyncssh.connect(host=self.request.deviceIPAddress,
                    port=22,
                    username=self.request.userName,
                    password=cli_password,
                    client_keys=None,
                    known_hosts=None,
                    connect_timeout=15)
output = await conn.run('show version')
print(output.stdout)

output.stdout returns the command output along with the banner/MOTD set in the device.

====================================================================
***** This is a Pre-Produciton Lab device *******
****** This device is used for testing *********
=====================================================================
Cisco IOS XE Software, Version 17.03.03
Cisco IOS Software [Amsterdam], ASR1000 Software (X86_64_LINUX_IOSD-UNIVERSALK9-M), Version 17.3.3, RELEASE SOFTWARE (fc7)
Technical Support: http://www.cisco.com/techsupport
Copyright (c) 1986-2021 by Cisco Systems, Inc.
Compiled Thu 04-Mar-21 12:36 by mcpre

asyncssh version 2.9.0

I really need only the command output of the show command here. Is there any option to hide the banner text from the run command output?

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ronfcommented, Sep 17, 2022

Unfortunately, there’s nothing asyncssh can really do to help you find the boundary between the banner and the beginning of command output, at least not if the target device repeats the banner on every command you run.

If you can control what goes in the banner, you could try searching for some unique text in that, and that could help you strip out the pieces you don’t need. Alternately, if you know the command you are running is always a fixed number of lines of output, you could just throw away everything before that last number of lines. If there’s a command that lets you echo some text, you could also try doing that before the command you want the output of, and searching for that text as a way to know where the split is. In the end, though, it’s really between you and the target system.

0reactions
ronfcommented, Sep 24, 2022

Typically, the “–MORE–” is handled by sending a command to disable paging on the device. The exact command varies from one device to another, but here are a couple I’ve run across:

“terminal length 0” on some Cisco devices “set cli screen-length 0” on some Juniper devices

Once you send this command (followed by a newline), you should be able to receive large amounts of output without sending input to go to the next page.

As for the separator, just make sure what you set is something in readuntil() that’s unique enough to not match any of the command output. Otherwise, you might not get all the output, as you’d be returning before all the output is read.

Running multiple command on a single session should always work fine. The case that doesn’t always work is opening multiple sessions on a single connection and running commands in separate sessions (to make it easier to know when you have all the output without having to scan for a prompt).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Banner and Message Commands - Cisco
To display the configured banner and MOTD, use the show running-config banner-motd command in privileged EXEC mode. show running-config banner-motd [{banner | ...
Read more >
Suppress banner for `ssh` or `scp` - Unix Stack Exchange
Specifies whether sshd(8) should print /etc/motd when a user logs in interactively. (On some systems it is also printed by the shell, /etc/ ......
Read more >
SSH client option to suppress server banners?
I want to keep Banner /path/to/sometxt serverside; I would like to pass an option under specific conditions so that Banner is not printed...
Read more >
How to Remove the Banner Message in PowerShell
I achieve this for Windows PowerShell in Windows Terminal by opening the terminal, typing notepad $profile (if it asks you to create the...
Read more >
Turn off the login banner in Linux or Unix .hushlogin file
Here is a quick tip that explains how to hide and turn off annoying ... The first one is /etc/motd, and the second...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found