0

Hi
I am working with shell scripting language (I am new to it). I have 6 different linux machines. I have access to machine A. Through machine A and using ssh -l <username> <ip_address>, I can connect to B. B has access to C, D, and E only (A cant access them directly. It has to do so via B only). Similarly, F is accessible only via C.

I have to run certain commands on all the linux machines (for eg, pwd and ls -lrt) from my system "A". How can I automate that thing? I mean is it possible in this scenario to execute script on machine A, which itself connects to all other machines as shown in figure and give me output of commands executed (via script only) on all machines as a text file in machine A?

I wrote a shell script. On execution of this script on machine A, it connects to machine B. And then, nothing more happens i.e. rest of the script is not executed. When I press Ctrl + D on machine B, script again starts executing. That is my problem because it is executing commands on machine A only, nothing on machine B. I want the script to keep running even thought the machine is now changed. What i feel the problem is, the machine B has no access to script. So, I need a workaround for how to do that.

If it is not possible in shell, which scripting language will be good for what I want to do?

I googled but the search results are not what I am looking for :( enter image description here

4
  • do you write something?
    – Farvardin
    May 26, 2014 at 4:45
  • I wrote a shell script, it connects me to machine B. But as the script is running on machine A, all the other steps that i want to execute on machine B is not happening. That is why I asked this question. May 26, 2014 at 5:01
  • can you share your code?
    – Farvardin
    May 26, 2014 at 5:55
  • I dont suggest you to handle this requirement using ssh client tool. SSH client interface for this requirement is limit . You might need some distributed software which handle such requirement. May 26, 2014 at 6:03

2 Answers 2

1

This may meet your issue:

ssh <username>@<hostname> "<your_command>"

More than one command, use “;” to seperate.

Good Luck!

1

I think splitting up code on different machines will help in your case but this will increase your manageability task,

one solution could be,

write scripts on respective nodes for tasks which you want to perform on them and just call those scripts using ssh from their parent node.

write a script/run a command on node A like

ssh user@nodeB "execute script on B(nodeBscript.sh)" 

whatever you want to perform on B, write it in a script nodeBscript.sh

now in nodeBscript.sh, call those scripts which are present on node C,D,E and performing the required tasks.

like,

ssh user@nodeC "nodeCscript.sh"
ssh user@nodeD "nodeDscript.sh"
ssh user@nodeE "nodeEscript.sh"

and similar chain goes till end. This allows you to achieve your goal. if you want you can redirect your output in files which are shared by NFS so that you can access those files from your machine A also.

another solution(which I guess you have already tried)

write all in a script like,

ssh user@nodeB "ssh user@nodeC 'your command'" > outputC
ssh user@nodeB "ssh user@nodeD 'your command'" > outputD
ssh user@nodeB "ssh user@nodeE 'your command'" > outputE

and this also should work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.