0

After logging in to a remote machine i want to "cd" to a particular directory and execute a command in the "exec_command" using the paramico module . But unable to do that. Am using ";" in between two commands but still unable to get the expected output.

import paramiko

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect("10.73.73.242", username="root", password="dangerous")
print 'running remote command'
stdin, stdout, stderr = ssh.exec_command("cd /usr/ABC/PGMS;pwd")
x = stdout.readlines()
print "VALUES",x
z=stderr.readlines()  
print "err are",z
stdin, stdout, stderr = ssh.exec_command("ls")
x = stdout.readlines()
print "VALUES ARE AGAIN",x
ssh.close()

Here i want to change dir to a directory "/usr/ABC/PGMS" execute "pwd" but its not working. Am clueless about what am doing wrong.

The output is as below

running remote command

VALUES ['/root\n']

err are ['bash: line 0: cd: /usr/ABC/PGMS/: No such file or directory\n']

VALUES ARE AGAIN ['Desktop\n', 'Documents\n', 'autoinst.xml\n', 'bin\n', >'dup_rm_ordr.py\n', 'fullwrite.log\n', 'inst-sys\n', 'pexpect-2.3\n', >'pexpect-2.3.tar.gz\n', 'read_print_matrix.py\n', 'remove_dup.py\n', >'runlog\n']

Still "pwd" shows the /root dir and lists the files and directories in /root.

Community
  • 1
  • 1
s.patra
  • 147
  • 1
  • 9
  • https://stackoverflow.com/a/37087098/267540 – e4c5 Jun 03 '17 at 09:53
  • May I know the reason what is going wrong here(while using paramico)? Actually I followed this after seeing the below link. https://stackoverflow.com/questions/8932862/how-do-i-change-directories-using-paramiko/11728118#11728118 – s.patra Jun 03 '17 at 14:19

0 Answers0