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?