Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
229 views
in Technique[技术] by (71.8m points)

python - SSH to machine through a middle host

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:

  • cp files from local machine to remote nodes
  • run a program on each node
  • retrieve files from the nodes to my local machine
  • maybe make it possible to copy over a fortran program and compile it on the nodes and also to check the nodes to see if any programs are running.

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You don't need Python to do this. Check the ProxyCommand configuration option for SSH. Here is a tutorial that explains the details.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...