Execution python-paramiko -
i trying execute command remote machine through python
ssh = paramiko.sshclient() ssh.set_missing_host_key_policy(paramiko.autoaddpolicy()) ssh.connect(server_ip, username='root', password='xxxxx') stdin, stdout, stderr = ssh.exec_command( "tar -c /home -xzf /home/tests.tar.gz;dos2unix /home/tests/run.py;chmod +x /home/tests/run.py;/home/tests/run.py>/home/tests/log.txt" )
it seems last command /home/tests/run.py>/home/tests/log.txt
not working log.txt
not having values, same works if /home/tests/run.py>/home/tests/log.txt
on remote machine terminal.
how resolve ?
thanks in advance
you not transporting client session :
ssh = paramiko.sshclient() ssh.set_missing_host_key_policy(paramiko.autoaddpolicy()) ssh.connect(server_ip, username='root', password='xxxxx') #note next line missing ssh_session = ssh.get_transport().open_session()
then (after declaration of ssh_session) may use ssh_session.exec_command(. . .)
.
try see if works.