如何存储 bash 脚本 ssh 调用的响应而不是调用本身?
我通过一个脚本在大约 150 台 RHEL 服务器上执行数据收集,该脚本被复制 (scp) 到每台服务器,然后通过 ssh 运行。在监视服务器上,我有:
H="ssh cshoults@ /usr/local/sc/collect.sh $SENDER $OUTPUTMETHOD "
RESULT=`$H`;
echo $RESULT;
该脚本返回以冒号分隔的九个值。然后,我使用如下内容设置九个变量:
HST=`$H | awk -F' : ' '{ print $1}`
但是,我可以通过速度判断它每次都会发送到远程服务器,而不是发送到服务器一次并将响应设置为字符串。现在已经很晚了,我对此感到恼火。有人可以帮我回答这个问题吗?如果我说 HST=
$RESULT...` 它会尝试执行该命令并给我找不到命令,所以我知道这是不对的。
I'm performing data collection on about 150 RHEL servers through a script that gets copied (scp) out to each server, then run through ssh. On the monitoring server, I have:
H="ssh cshoults@ /usr/local/sc/collect.sh $SENDER $OUTPUTMETHOD "
RESULT=`$H`;
echo $RESULT;
The script returns nine values separated by colons. I'm then setting nine variables with something like this:
HST=`$H | awk -F' : ' '{ print $1}`
However, I can tell by the speed that it's going out to the remote server each time instead of going to the server once and setting the response to a string. It's late in the day and I'm getting irritated by this one. Can someone answer this for me? If I say HST=
$RESULT...` it tries to execute the command and gives me command not found, so I know it's not right.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果不想每次都去服务器,就保存结果。
If you don't want to go to the server each time, save the result.
以下是对 Dietrich 回应的补充:
Here's an enhancement to Dietrich's response:
顺便说一句,您可以使用特殊形式的
set
拆分为$@
;By the by, you can split into
$@
with a special form ofset
;