Hi Friends,
I am new to python, kind of migrating from bash to python. here is thing I am trying to do with my pythong script.
ssh system and get some info from that system. I want it all automated. here is where I am strucked
script is pormpting me for ssh password
given below is my script
OS : fedora20
sshd daemon is running.
Code:
#!/usr/bin/python
from subprocess import Popen, PIPE
from sys import argv
script, ip = argv
username="test"
passwd="password"
command = "ssh -l %r %r 'echo hello >> /tmp/test.txt'" % (username,ip)
proc = Popen([command], stdin=PIPE,stdout=PIPE,stderr=PIPE,shell=True)
#proc.communicate(passwd)
proc.communicate("password\n")
How I execute script
Code:
$python ./python_ssh.py 192.168.1.20
test@192.168.1.20's password:
when I run above script it prompts me for password. Kindly suggest me where I am doing wrong, if any good e-book or link for learning subprocess is also welcome.
regards