<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Thanks,&nbsp;<div><br></div><div>Your code works as&nbsp;expected! Can you tell me what your code is doing different than mine?&nbsp;<br><div><br></div><div>Charlie</div><div><br><div><div>On Jun 23, 2009, at 3:06 PM, vince spicer wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">os.system is not the best way to handle this you may want to look into<br>the subprocess module<br><br>however:<br><br>import os<br> <br> username = 'charlie'<br> private_key = '/path/to/key'<br> ssh = '/usr/bin/ssh'<br> command = 'hostname &amp;&amp; df -h &amp;&amp; exit'<br> <br> servers = ['172.16.1.1', '172.16.12.2', '172.16.1.3']<br> <br> for host in servers:<br>&nbsp;&nbsp;&nbsp; os.system("ssh %s@%s -i %s %s" %(username, host, private_key, command)<br><br><br><br><div class="gmail_quote">On Tue, Jun 23, 2009 at 2:01 PM, Charlie Reddington <span dir="ltr">&lt;<a href="mailto:charlie.reddington@gmail.com">charlie.reddington@gmail.com</a>&gt;</span> wrote:<br> <blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hi,<br> <br> I'm very very green when it comes to python. I know bash better than python, so I figured a good way to learn things was covert my bash stuff to python. So here goes...<br> <br> Here's a quick example of the code I have that is broken.<br> <br> import os<br> <br> username = 'charlie'<br> private_key = '/path/to/key'<br> ssh = '/usr/bin/ssh'<br> command = 'hostname &amp;&amp; df -h &amp;&amp; exit'<br> <br> servers = ['172.16.1.1', '172.16.12.2', '172.16.1.3']<br> <br> for host in servers:<br> &nbsp; &nbsp;print(os.system(ssh -l username -i private_key host command))<br> <br> What I'm trying to do is is, is use ssh with a private key. That way I can quickly run some remote commands on a few hundred servers in a quick way to do stuff (disk usage, top, etc).<br> <br> When I run this, I get errors like this for every host in my list.<br> <br> Warning: Identity file private_key not accessible: No such file or directory.<br> ssh: Could not resolve hostname i: nodename nor servname provided, or not known<br> 65280<br> <br> My first thoughts are, it's not passing my variables to the function the way I'd expect.<br> <br> So my questions are...<br> <br> 1.) Is it nessacary to put my IP's in quotes?<br> 2.) When I call a variable in a function (like os.system() or print()) I don't use $'s right?<br> 3.) Am I putting variables in my functions properly? Can I put variables like this in there?<br> <br> Thanks for any help.<br> <br> Charlie<br> <br> _______________________________________________<br> Tutor maillist &nbsp;- &nbsp;<a href="mailto:Tutor@python.org" target="_blank">Tutor@python.org</a><br> <a href="http://mail.python.org/mailman/listinfo/tutor" target="_blank">http://mail.python.org/mailman/listinfo/tutor</a><br> </blockquote></div><br></blockquote></div><br></div></div></body></html>