In my work with my professor I have to ssh into our server and from there I ssh into each node to run our programs. I am trying to write a python program that will let me do everything that I need to do on the remote node from my local machine. The commands that I will be running on the nodes are:
Right now I make my input files on my local machine, scp them to the server, then I copy the files to each node and run our fluid_dynamics program on each node. I then do the reverse to get our output back to my local machine.
I was looking at paramiko but I can not figure out how I can use it to get from my local machine to the nodes because I must go through the server. local -ssh--> server -ssh--> nodes
Is there a way to do this in python or should I try something else such as: using:
os.system(ssh -t server ssh node 'command')
or making a bash scripts on the server for each of the different commands (compile.sh, move_inputs.sh, retrieve_outputs.sh) and then just connecting to the server and running the bash scripts.
Sorry if this doesn't make sense or if it is worded badly, any help is appreciated.
Additional Info: The reason I am using python is because I want the program to be able to make the input files, send them to the nodes and retrieve the output files, and to finally generate graphs of our data. I already have some code to generate our input files and to make the graphs from the outputs.
For remote port forwarding, enter the remote SSH server forwarding port in the Source Port field and in Destination enter the destination host and IP, for example, localhost:3000 . If setting up dynamic forwarding, enter only the local SOCKS port in the Source Port field.
You don't need Python to do this. Check the ProxyCommand configuration option for SSH. Here is a tutorial that explains the details.
You can do it with Paramiko:
proxy_command = 'ssh -i %s %s@%s nc %s %s' % (proxy_key, proxy_user, proxy_host, host, 22)
proxy = paramiko.ProxyCommand(proxy_command)
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(host, username=user, password=password, sock=proxy)
stdin, stdout, stderr = client.exec_command('echo HELLO')
print "Echo: %s" % (", ".join(stdout.readlines()))
client.close()
It works with SFTPClient
too:
proxy_command = 'ssh -i %s %s@%s nc %s %s' % (proxy_key, proxy_user, proxy_host, host, 22)
proxy = paramiko.ProxyCommand(proxy_command)
transport = paramiko.Transport(proxy)
transport.connect(username=user, password=password)
sftp = paramiko.SFTPClient.from_transport(transport)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With