参考网址:
http://mp.weixin.qq.com/s?__biz=Mzg4NDA1MTAyOQ==&mid=2247486040&idx=1&sn=19c3d0169cbc066f628f42f36510b03b&chksm=cfbf5762f8c8de743ac21c61726759dfeda7254f47a07efea73cd1e459a38b0dbbe5dc84856b&mpshare=1&scene=24&srcid=1010oJrh1GgqZ1SLbeeuavbV&sharer_sharetime=1665380161162&sharer_shareid=a139fd462e16cb08ad1dc90045048a03#rd
1 使用分号隔开
使用 分号 ;
来隔开命令
-
附带1条命令
ssh User@Host 'source /etc/profile'
-
附带多条命令
ssh User@Host 'source /etc/profile ; uptime'
2 使用管道符号隔开
使用管道|
来隔开命令
-
附带1条命令
ssh User@Host 'source /etc/profile'
-
附带多条命令
ssh User@Host 'source /etc/profile | uptime'
3 使用写EOF的方式
同样适用于一条 / 多条命令
ssh User@Host << EOF
> ls -al
> source /etc/profile
> EOF
4 使用脚本的方式
使用脚本的方式花样就更多了,例如有一个脚本myinit.sh
在/home/admin/code/
下面
myinit.sh
#!/bin/bash
source /etc/profile
ls -al
远程连接服务器
ssh User@Host 'bash -s' < /home/admin/code/myinit.sh