【发布时间】:2015-10-20 07:47:49
【问题描述】:
TASK - 通过 SSH 连接到 650 个服务器并从中获取一些详细信息,然后将完成的服务器名称写入不同的文件中。如何以更快的方式做到这一点?如果我做正常的 ssh 需要 7 分钟。所以,我阅读了 awk 并编写了以下 2 个代码。
你能解释一下下面代码的区别吗?
代码 1 -
awk 'BEGIN{done_file="/home/sarafa/AWK_FASTER/done_status.txt"}
{
print "blah"|"ssh -o StrictHostKeyChecking=no -o BatchMode=yes -o ConnectTimeout=1 -o ConnectionAttempts=1 "$0" uname >/dev/null 2>&1";
print "$0" >> done_file
}' /tmp/linux
代码 2 -
awk 'BEGIN{done_file="/home/sarafa/AWK_FASTER/done_status.txt"}
{
"ssh -o StrictHostKeyChecking=no -o BatchMode=yes -o ConnectTimeout=1 -o ConnectionAttempts=1 "$0" uname 2>/dev/null"|getline output;
print output >> done_file
}' /tmp/linux
当我为 650 台服务器运行这些代码时,代码 1 需要 - 30 秒,代码 2 需要 7 分钟? 为什么会有这么大的时差?
文件 - /tmp/linux 是 650 个服务器的列表
【问题讨论】:
标签: linux bash awk ssh parallel-processing