gpt4 book ai didi

bash - bash脚本以ssh并运行命令

转载 作者:行者123 更新时间:2023-12-02 14:13:59 25 4
gpt4 key购买 nike

我想SSH到一个节点并在那里运行命令,然后退出。对于所有点头重复此操作。脚本非常简单

#!/bin/bash
NODES="compute-0-0 compute-0-1 compute-0-2 compute-0-3"
for i in $NODES
do
ssh $i
ls -l /share/apps
rpm -ivh /share/apps/file.rpm
exit
done

但是问题是,在ssh之后,缺少 ls -l命令。因此,命令提示符等待输入!

有什么办法解决吗?

更新:

我将循环体修改为
ssh $i <<END
ls -l /share/apps
exit
END

但是我明白了
./lst.sh: line 9: warning: here-document at line 5 delimited by end-of-file (wanted `END')
./lst.sh: line 10: syntax error: unexpected end of file

最佳答案

试试这个

    #!/bin/bash
NODES="compute-0-0 compute-0-1 compute-0-2 compute-0-3"
for i in $NODES
do
ssh $i "ls -l /share/apps;rpm -ivh /share/apps/file.rpm;exit;"
done

关于bash - bash脚本以ssh并运行命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38239910/

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