UNIX 菜鸟请教 V 友, linux A 脚本 ssh 另外一台机器执行 A 机器的一个脚本

2016-11-22 13:00:36 +08:00
 Alain1995

最终目的

问题:

有两个想法

还有一点点小疑问

更改完系统语言之后能做到不重启不注销就能显示更改之后的效果吗?

跪谢= =

2870 次点击
所在节点    Linux
10 条回复
TheCure
2016-11-22 13:06:19 +08:00
ansible test -m script -a "test.sh"
knightdf
2016-11-22 13:06:27 +08:00
在脚本中 echo/print 出来就行了
例子:
> ssh root@192.168.1.213 "ping v2ex.com" >> test 2>&1
> cat test
> PING v2ex.com (14.152.44.135) 56(84) bytes of data.
64 bytes from 14.152.44.135: icmp_seq=1 ttl=52 time=21.3 ms
64 bytes from 14.152.44.135: icmp_seq=2 ttl=52 time=21.3 ms
64 bytes from 14.152.44.135: icmp_seq=3 ttl=52 time=21.2 ms
64 bytes from 14.152.44.135: icmp_seq=4 ttl=52 time=21.4 ms
64 bytes from 14.152.44.135: icmp_seq=5 ttl=52 time=21.2 ms
64 bytes from 14.152.44.135: icmp_seq=6 ttl=52 time=27.7 ms
64 bytes from 14.152.44.135: icmp_seq=7 ttl=52 time=20.3 ms
64 bytes from 14.152.44.135: icmp_seq=8 ttl=52 time=20.5 ms
64 bytes from 14.152.44.135: icmp_seq=9 ttl=52 time=20.4 ms
64 bytes from 14.152.44.135: icmp_seq=10 ttl=52 time=20.2 ms

--- v2ex.com ping statistics ---
10 packets transmitted, 10 received, 0% packet loss, time 9030ms
rtt min/avg/max/mdev = 20.279/21.586/27.712/2.086 ms
Alain1995
2016-11-22 13:12:07 +08:00
@callofmx 想要那种缺省的命令及工具。= =
Alain1995
2016-11-22 13:12:42 +08:00
@knightdf 谢谢,大概知道了。我去试试 0.0
ceyes
2016-11-22 13:56:14 +08:00
tips
1. 可以用 ssh-copy-id 将本机的公钥拷贝到远程机器的 authorized_keys 文件中,实现无密码登录。可以在部署的时候就把公钥都装好,或用 tcl/expect 先完成公钥拷贝。
2. ssh LinuxB 后面可以直接跟命令,远端的执行的结果就在 A 的标准输出上, ssh 的返回值就是远端的命令返回值。
3. 还可以设置一个 NFS ,在 LinuxB 上 mount 作为 worksace ,执行脚本和 log 都在这个 workspace 中。
Alain1995
2016-11-22 14:57:07 +08:00
@ceyes 还有一点小问题,就是判断被执行端的 linux B 是否已经存在当前 linux A 的公钥?
ceyes
2016-11-22 15:26:50 +08:00
@Alain1995 ssh <user>@<IP_of_LinuxB> exit && echo "have key" || echo "no key"
gihnius
2016-11-22 20:50:11 +08:00
linux_A $ ssh you@linux_B 'bash -s' < your_local_script_on_A.sh sh-args...
Alain1995
2016-11-22 21:06:37 +08:00
@ceyes 谢谢
Alain1995
2016-11-22 21:06:59 +08:00
@gihnius 谢谢

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/322339

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX