I’m attempting to write a simple one-line script to ssh into a remote host, CD to my Django app’s directory, and run manage.py shell. So far I have:
ssh -i mysite.pem root@remotehost "cd /usr/local/myapp; /bin/bash -i -c \"python manage.py shell;\""
This seems to work with the caveat that I can’t see any output from my commands. All I see is:
Python 2.6.4 (r264:75706, Jun 4 2010, 18:20:16)
[GCC 4.4.4 20100503 (Red Hat 4.4.4-2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
And then any input I give, but when I press enter, I don’t seem to see anything from stdout. However, if I enter syntactically invalid Python, I do see a Python traceback from stderr.
What else am I missing?
Pass the
-toption tossh.By default, running
ssh host commanddoesn’t allocate a proper pseudo-tty, which makes any program that uses terminal escape routines, such as line-editing interpreters, etc. fail.Therefore, your one-liner can be:
It is possible to, but no need to wrap in another layer of bash like you did. Remember that
ssh host commandactually passescommandas a string to the user’s default shell (which is why you can do shell-specific things likecd), so I can’t think of a reason why you’ll need to runbashwithinbash.