Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
example paramiko script that tries to run an interactive command that needs a terminal
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