viernes, mayo 19, 2017

Paramiko - Python

pip install paramiko

>>> import paramiko
>>> ssh = paramiko.SSHClient()
>>> ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
>>> ssh.connect('192.168.10.160', username='usuario', password='clave')
>>> stdin, stdout, stderr = ssh.exec_command("ping -c 3 yahoo.com")
>>> stdout.readlines()
[u'PING yahoo.com (206.190.36.45) 56(84) bytes of data.\n', u'64 bytes from ir1.fp.vip.gq1.yahoo.com (206.190.36.45): icmp_seq=1 ttl=49 time=203 ms\n', u'64 bytes from ir1.fp.vip.gq1.yahoo.com (206.190.36.45): icmp_seq=2 ttl=49 time=204 ms\n', u'64 bytes from ir1.fp.vip.gq1.yahoo.com (206.190.36.45): icmp_seq=3 ttl=49 time=203 ms\n', u'\n', u'--- yahoo.com ping statistics ---\n', u'3 packets transmitted, 3 received, 0% packet loss, time 6220ms\n', u'rtt min/avg/max/mdev = 203.043/203.732/204.230/0.503 ms\n']
>>> stdin.close()
>>> ssh.close()





source:
http://jessenoller.com/blog/2009/02/05/ssh-programming-with-paramiko-completely-different

No hay comentarios.:

Kill process in one console command line

example:   $ sleep 3600 & [ 1 ] 2225 $ sleep 3600 & [ 2 ] 2226 $ sleep 3600 & [ 3 ] 2227 $ sleep 3600 & ...