Execute commands on a remote machine using SSH locally
Source: Internet
Author: User
Use SSH $ RemoteNode & lt; cmd & gt; to execute commands on a remote machine, for example, sshuser @ nodels/local will execute the ls/local command on the remote machine. if you want to execute multiple consecutive commands on the remote machine... use SSH $ RemoteNode locally to execute commands on a remote machine You can execute commands on a remote machine. for example, ssh user @ node ls/local will execute the ls/local command on the remote machine. if you want to execute multiple commands consecutively on the remote machine, these commands can be enclosed in single or double quotes, for example, ssh user @ node "cd/local; pwd; ls "if you want to start the command on the remote machine locally and then return it, you can use ssh user @ node"/local/x. sh 1>/dev/null 2> & 1 & "Note that if there is no" ", for example, ssh user @ node cd/local; ls, ls will only execute the cd/local command, if the ls command is executed locally and double quotation marks or single quotation marks are added, the enclosed command is used as a parameter of the ssh command, so it will be executed remotely. Differences between single quotation marks and double quotation marks in the ssh command: An example is provided to illustrate the problem. assume that JAVA environment variables are configured on the local machine, run echo $ JAVA_HOME =/opt/jdk locally. if you want to view the JAVA environment variables on a remote machine, you can only use single quotes. ssh user @ node 'echo $ Java ', $ JAVA in ''is not parsed by shell, but is treated as a string. echo $ JAVA is passed to ssh. if we use ssh user @ node" echo $ JAVA ", then shell will first parse $ JAVA and get its value, then the command will become ssh user @ node 'echo/opt/jdk'
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.