1
votes

I am using Python to ssh over to remote server using Paramiko and run shell script to execute commands

.py file:

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(host, username=username, password=password)
print("Connected")
stdin, stdout, stderr = ssh.exec_command(myscript)

# read the standard output and print it
print(stdout.read().decode())
# print errors if there are any
err = stderr.read().decode()
if err:
    print(err)
ssh.close()

Unix script:

cd /usr/data
pwd
read -r username  
echo "$username"

The output will be:

/usr/data

It doesn't allow be to enter the input for username variable and doesn't display it.

How can I achieve this using Python (pycharm ide) and Unix?

1

1 Answers

0
votes

You are maybe looking for:

stdin, stdout, stderr = ssh.exec_command(myscript)

interactive_shell(stdin.channel)

Where interactive_shell comes from Paramiko interactive.py demo.