1

I have a script where I am sshing into multiple boxes and updating the date. My issue is after successfully sshing in my second command is not being executed. I am doing this correctly?

Code:

command1 = "/usr/bin/ssh %(username)s@%(hostname)s" % locals()
command2 = " /usr/bin/date -s\"%(easterndate)s\"" % locals()

p = pexpect.spawn((command1 + command2), timeout=360)

Output:

-Desktop:~/Desktop$ ./pexpect_test.py /usr/local/lib/python2.6/dist-packages/pytz/tzinfo.py:5: DeprecationWarning: the sets module is deprecated from sets import Set

command1 + command2 is: /usr/bin/ssh id@something.url.com /bin/date -s"Thu Mar 28 17:21:52 EDT 2013"

Initial pexpect command output: 1

logging into box

login successful

Setting the time...

WorkerBee
  • 683
  • 3
  • 11
  • 22
  • Could you include in your question an example of what's actually being output when you run this program? – Martin Atkins Mar 28 '13 at 22:14
  • @MartinAtkins I updated the post to include the requested information. – WorkerBee Mar 29 '13 at 14:30
  • Where is all of that additional logging coming from? It looks like there's more to your program than you included in your snippet. If all you want to do is connect to a remote host and run a command, you might find the answers to this question useful as alternatives: http://stackoverflow.com/questions/3586106/perform-commands-over-ssh-with-python – Martin Atkins Mar 29 '13 at 15:01
  • Don't know if it's the issue, but quoting is always delicate. Try adding `print (command1 + command2)`, and run on the prompt the exact same command. – Armin Rigo Mar 29 '13 at 17:39

0 Answers0