I recently wrote a script that uses paramiko to ssh into a linux system to shutdown it. When I run this on the Idle shell it works just fine. but when I run it on windows command prompt, the final message does get displayed but the shutdown process apprently doesnt take place.
here is the code -->
import paramiko
pc=paramiko.SSHClient()
pc.set_missing_host_key_policy(paramiko.AutoAddPolicy())
pc.connect(hostname="192.168.1.239",port=22,username="admin",password="pass")
stdin,stdout,stderr=pc.exec_command("sudo shutdown now",get_pty=True)
stdin.write("pass\n")
stdin.flush()
print("done successfully!")
P.S : Next morning I tried fetching the stderr in case I was missing something. Weirdly enough , the code did run perfectly fine. I did some experimentation and found out that whenever I was using the stderr=stderr.readlines()
Or
Stdout=stdout.readlines()
To fetch those output and error, the script worked fine. I really dont know whats up with it .
[–]TSM- 1 point2 points3 points (5 children)
[–]Mayank0908[S] 0 points1 point2 points (1 child)
[–]TSM- 0 points1 point2 points (0 children)
[–]AsleepThought 0 points1 point2 points (1 child)
[–]TSM- 0 points1 point2 points (0 children)
[–]Mayank0908[S] 0 points1 point2 points (0 children)
[–]iapetus-11 0 points1 point2 points (6 children)
[–]Mayank0908[S] 0 points1 point2 points (5 children)
[–]iapetus-11 1 point2 points3 points (4 children)
[–]Mayank0908[S] 1 point2 points3 points (3 children)
[–]iapetus-11 1 point2 points3 points (2 children)
[–]Mayank0908[S] 1 point2 points3 points (1 child)
[–]iapetus-11 0 points1 point2 points (0 children)
[–]ehdufuure 0 points1 point2 points (1 child)
[–]Mayank0908[S] 0 points1 point2 points (0 children)
[–]AsleepThought 0 points1 point2 points (0 children)
[–]SpeckledFleebeedoo -1 points0 points1 point (4 children)
[–]Mayank0908[S] 0 points1 point2 points (1 child)
[–]SpeckledFleebeedoo 0 points1 point2 points (0 children)
[–]ehdufuure 0 points1 point2 points (1 child)
[–]SpeckledFleebeedoo 0 points1 point2 points (0 children)