Shell remote execution:
It's often necessary to execute some shell commands remotely to other nodes, and if you ssh to each host again, it's a hassle, so you can have a centralized management approach. Describes how the two shell commands are executed remotely.
Prerequisites:
Configure SSH password-free login
for a simple command:
If you are simply performing several commands, then:
SSH " cd/home; LS "
Basic can complete the common use for Remote node management, a few points to note:
- Double quotes, must have. If you do not add double quotes, the second LS command executes locally
- Semicolon, separated by a semicolon between two commands
How to script:
Some remote execution of the command content, a single command can not be completed, consider the scripting way to implement:
#!/bin/bashssh [email protected] >/dev/null2>&1 << /hometouch abcdefg.txtexiteeooffechodone!
The remote execution of the content between "<< Eeooff" to "Eeooff", the operation on the remote machine is in it, note the point:
- << Eeooff,ssh until the end of the Eeooff, Eeooff can be modified to other forms.
- Redirection is intended to not show the remote output.
- Before the end, add exit to exit the remote node