Created
August 19, 2012 19:05
-
-
Save rtomaszewski/3397079 to your computer and use it in GitHub Desktop.
example paramiko script that tries to run an interactive command that needs a terminal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import paramiko | |
bastion_ip='ip' # you have to edit and provide valid IP address | |
bastion_pass='pass' # you have to edit it and provide valid password | |
ssh = paramiko.SSHClient() | |
ssh.set_missing_host_key_policy( paramiko.AutoAddPolicy() ) | |
ssh.connect(bastion_ip, username='root', password=bastion_pass) | |
chan = ssh.invoke_shell() | |
# other cloud server | |
priv_ip='private_ip' # you have to edit it and provide valid private IP 10.176.0.0/12 | |
passw='pass' # valid password | |
test_script='/root/check_rackconnect.sh' | |
def run_cmd(cmd): | |
stdin, stdout, stderr = ssh.exec_command(cmd) | |
for l in stdout : | |
print("stdout : %s" % l.strip()) | |
for l in stderr: | |
print("stderr : %s" % l.strip()) | |
cmd='pwd; ls; date' | |
print('\n test 1\n cmd %s\n' % cmd) | |
run_cmd(cmd) | |
scp_opt="" | |
cmd='scp -q ' + scp_opt + ' -o NumberOfPasswordPrompts=1 -o StrictHostKeyChecking=no %s root@%s:~/; echo $? done.' % ( test_script, priv_ip ) | |
print('\n test 2\n cmd %s\n' % cmd) | |
run_cmd(cmd) | |
scp_opt="-v" | |
cmd='scp -q ' + scp_opt + ' -o NumberOfPasswordPrompts=1 -o StrictHostKeyChecking=no %s root@%s:~/; echo $? done.' % ( test_script, priv_ip ) | |
print('\n test 3\n cmd %s\n' % cmd) | |
run_cmd(cmd) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment