I am using pxssh
to log in and issue some commands on a remote server.
My code looks like:
def login(self):
try:
self.connection = pxssh.pxssh()
self.password = getpass.getpass('Password: ')
self.connection.login(self.host, self.username, self.password)
except pxssh.ExceptionPxssh:
raise("Failed to login.")
def send_command(self, command):
try:
self.connection.sendline(command)
print(self.connection.before)
except pxssh.ExceptionPxssh:
print("Failed to execute command.")
def logout(self):
try:
self.connection.logout()
except pxssh.ExceptionPxssh:
print("Failed to logout.")
The output of running some commands is:
Downloading Terraform package.
b" unset PROMPT_COMMAND\r\n\x1b]0;test_user@d01c1ad4ad1c: ~\x07\x1b[01;32mtest_user@d01c1ad4ad1c\x1b[00m:\x1b[01;34m~\x1b[00m$ PS1='[PEXPECT]\\$ '\r\n"
Unzipping Terraform package
b" unset PROMPT_COMMAND\r\n\x1b]0;test_user@d01c1ad4ad1c: ~\x07\x1b[01;32mtest_user@d01c1ad4ad1c\x1b[00m:\x1b[01;34m~\x1b[00m$ PS1='[PEXPECT]\\$ '\r\n"
Cleaning up the terraform_0.11.2_linux_amd64.zip package
b" unset PROMPT_COMMAND\r\n\x1b]0;test_user@d01c1ad4ad1c: ~\x07\x1b[01;32mtest_user@d01c1ad4ad1c\x1b[00m:\x1b[01;34m~\x1b[00m$ PS1='[PEXPECT]\\$ '\r\n"
Move Terraform file
b" unset PROMPT_COMMAND\r\n\x1b]0;test_user@d01c1ad4ad1c: ~\x07\x1b[01;32mtest_user@d01c1ad4ad1c\x1b[00m:\x1b[01;34m~\x1b[00m$ PS1='[PEXPECT]\\$ '\r\n"
I would like to completely remove all lines in the output that contains unset
. Is there any attribute that does that or is there any workaround for that?
From the output of your commands I assume you are running linux.
As described here and here, it seems the PROMPT_COMMAND affects your prompt. To disable it try to run:
and for the permanent effect add this to
.bashrc
.