I am rather new to Linux and Paramiko, but the issue I am having is anytime I attempt to change a shell the remote Paramiko session will hang.
The remote host is in /etc/csh
by default
I am running various scripts, some require csh
and others require bash
. Any of my scripts running in csh
work properly since the remote host is in csh
by default.
To run the other scripts I need to be in bash
.
Whenever I attempt to change the shell using bash
or /bin/bash
paramiko connection will simply hang. I am using the following command to verify shells prior to connection and after attempting to temporarily change the shell to see what works, but nothing has. This is using Paramiko and Python 3.6.5.
Note: this also fails the other way around; if I put the remote host in bash
by default it will fail to switch to csh
main.py
connection = SSH.SSH(hostname, username, password)
connection.changeShell('echo $0 ; echo $shell; /bin/bash ; echo $shell ; echo $0')
This has also been tried as just bash
and chsh
SSH.py
class SSH:
client = None
def __init__(self, address, username, password):
print("Login info sent.")
print("Connecting to server.")
self.client = client.SSHClient() # Create a new SSH client
self.client.set_missing_host_key_policy(client.AutoAddPolicy())
self.client.connect(address, username=username,
password=password, look_for_keys=False) # connect
def changeShell(self, command):
print("Sending your command")
# Check in connection is made previously
if (self.client):
stdin, stdout, stderr = self.client.exec_command(command)
while not stdout.channel.exit_status_ready():
# Print stdout data when available
if stdout.channel.recv_ready():
# Retrieve the first 1024 bytes
alldata = stdout.channel.recv(2048)
while stdout.channel.recv_ready():
# Retrieve the next 1024 bytes
alldata += stdout.channel.recv(2048)
# Print as string with utf8 encoding
print(str(alldata, "utf8"))
stdin.close()
stdout.close()
stderr.close()
else:
print("Connection not opened.")