gpt4 book ai didi

linux - 连接两台服务器并获取数据

转载 作者:太空宇宙 更新时间:2023-11-04 05:49:06 25 4
gpt4 key购买 nike

我正在编写一个脚本来连接到服务器计算机并从中获取一些数据。我的命令顺序如下

ssh -tt user@server1 ssh -tt user@server2  
cd dir1/dir2
ls -1t name* | head 1

从服务器退出后应打印最后一个命令的结果

最佳答案

要在其他服务器上运行命令,您需要将其用作 ssh 的参数。

man ssh(缩写为 [...]):

Synopsis

ssh [...] destination [command]

[...]

If command is specified, it is executed on the remote host instead of a login shell.

为了说明,在第一步中,只有第二个命令被转换为这种形式。

ssh -tt user@server1
ssh -tt user@server2 'cd dir1/dir2; ls -1t name* | head 1'

现在第二个也必须被引用并用作第一次登录的参数:

ssh -tt user@server1 "ssh -tt user@server2 'cd dir1/dir2; ls -1t name* | head 1'"

确保转义双引号中的空格字符,例如“\$”

关于linux - 连接两台服务器并获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47143022/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com