enter code here
#!/usr/bin/python
import paramiko
import sys
import time
import Tkinter
import time, os, threading
from Tkinter import *
a=Tkinter.Tk()
#A function that logins and execute commands
def fn():
HOST=raw_input('Enter HOST IP: ')
USER=raw_input('Enter USER NAME: ')
PASS=raw_input('Enter PASSWORD: ')
client1=paramiko.SSHClient()
client1.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client1.connect(HOST,username=USER,password=PASS)
print "SSH connection to %s established" %HOST
com="cat /etc/motd"
print "Welcome to Account",
com1=raw_input("Enter the command:")
com2=raw_input("Enter if you you want to run multiple command:")
#Gather commands and read the output from stdout
stdin, stdout, stderr = client1.exec_command(com)
print stdout.read()
stdin, stdout, stderr = client1.exec_command( com1)
print stdout.read()
stdin, stdout, stderr = client1.exec_command( com2 )
print stdout.read()
client1.close()
top = os.system("sudo su -")
s = str(top)
print "Logged out of device %s" %HOST
b = Button(a, text='Welcome to the Login World', command=fn)
b.pack()
b.mainloop()
Output are below::
[root@xyz ~]#
Enter HOST IP: 10.12.132.143
Enter USER NAME: abc
Enter PASSWORD:*************
SSH connection to 10.129.136.150 established
Welcome to Account Enter the command:uptime;uname -a
Enter if you you want to run multiple command:
01:02:48 up 4 days, 15:28, 3 users, load average: 1.02, 1.01, 1.00
Linux 10.12.132.143 2.6.32-642.6.2.el6.x86_64 #1 SMP Mon Oct 24 10:22:33 EDT 2016 x86_64 x86_64 x86_64 GNU/Linux
[root@xyz ~]# -->this is the error it should login to 10.12.132.143 server but it is login to my master server
[root@xyz ~]#.
uname -aoutput, the commands get executed on the remote server. If you're expecting to have an interactive prompt on the remote server, this is not how you do it with paramiko. But it's not really clear what your question is.