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.