0

I have a small problem with paramiko. It seems that all commands are not executed like with a manual ssh session.

Let's focus on "history" shell command, even if my main concern is this command:

$ python /home/metrosim/src/urbansim/tools/make_indicators.py \
-x /home/metrosim/project_configs/paris_zone_ovh_km130110.xml \
-c /home/metrosim/data/paris_zone/base_year_data_a \
-i trip_generation -y [1999]

Both are working with manual ssh session, but not with paramiko, but simple commands like ls -lA work.

Here is my code :

stdin, stdout, stderr = ssh_client.exec_command('history')

print 'LINES : '
data = stdout.read().splitlines()
for line in data:
     print line
tshepang
  • 12,111
  • 21
  • 91
  • 136
Touki
  • 833
  • 2
  • 9
  • 20

1 Answers1

0

If you want to emulate a shell session, try using invoke_shell() instead of exec_command().

From the invoke_shell docs:

Request an interactive shell session on this channel. If the server allows it, the channel will then be directly connected to the stdin, stdout, and stderr of the shell.

Normally you would call get_pty before this, in which case the shell will operate through the pty, and the channel will be connected to the stdin and stdout of the pty.

When the shell exits, the channel will be closed and can't be reused. You must open a new channel if you wish to open another shell.

Alex L
  • 8,748
  • 5
  • 49
  • 75
  • In fact, I don't want to emulate a shell session. At first I just wanted to execute the long command, I've tried after to catch up the historic because this command wasn't working via paramiko, but was working via standard shell ssh. Anyway, why shouldn't I get what is printed by history in the stdout by executing 'history' ? – Touki Jan 18 '13 at 13:36