安徽响应式网站建设哪家有,相亲网站做期货现货贵金属的人,阿里巴巴中文站官网,茶庄网站模板SSH连接服务器后执行多条命令 大家平时有没有遇到自己连接云服务器#xff0c;ssh 连接上去之后#xff0c;发现自己的一些小工具用不了
例如go build无法使用 #xff0c;由于我们安装配置golang 环境的时候#xff0c;是在文件/etc/profile中写了配置#xff0c;因此需…SSH连接服务器后执行多条命令 大家平时有没有遇到自己连接云服务器ssh 连接上去之后发现自己的一些小工具用不了
例如go build无法使用 由于我们安装配置golang 环境的时候是在文件/etc/profile中写了配置因此需要source 一下/etc/profile
那么是否可以在ssh 连接上服务器的时候就可以立即自动执行这一类命令呢
我们的智慧无穷无尽小工具也是非常的多今天来讲述一下SSH连接服务器后执行多条命令可以如何做
1 使用分号隔开 使用 分号 ;来隔开命令
附带1条命令
ssh UserHost source /etc/profile 1 附带多条命令
ssh UserHost source /etc/profile ; uptime 1 2 使用管道符号隔开 使用管道|来隔开命令
附带1条命令
ssh UserHost source /etc/profile 1 附带多条命令
ssh UserHost source /etc/profile | uptime 1 3 使用写EOF的方式 同样适用于一条 / 多条命令
ssh UserHost EOF ls -al source /etc/profile EOF 1 2 3 4 4 使用脚本的方式 使用脚本的方式花样就更多了例如有一个脚本myinit.sh在/home/admin/code/下面
myinit.sh
#!/bin/bash
source /etc/profile ls -al 1 2 3 4 远程连接服务器
ssh UserHost bash -s /home/admin/code/myinit.sh 1 以上四种方式按需索取很可 ———————————————— 版权声明本文为CSDN博主「阿兵云原生」的原创文章遵循CC 4.0 BY-SA版权协议转载请附上原文出处链接及本声明。 原文链接https://blog.csdn.net/m0_37322399/article/details/115435025