linux 的 shell 脚本中的 for 循环需要帮助

Need help in for loop in kshell scripting for linux

有人能说说下面的工作原理吗?

server.ksh file contains the below.
n=   ### what does this do ? 
ssh $n date;

test 是一个包含 50 个服务器列表的文件。 现在我运行下面。

for a in `cat test`; do ksh server.ksh $a >> date$a & done

随便看看上面的内容,你可以说它只是打印所有服务器的日期并保存 o/p。但问题是它会影响所有服务器完全相同的时间!!(即不像传统的 for 循环一个接一个)。有人可以分解并解释一下吗?

# assign variable 'n' the value of the first input parameter to
# the server.ksh invocation; a server name in this case
n=

# make a ssh call to the server whose name is stored in
# variable 'n', on the remote host run the 'date' command
ssh $n date;

您的 while 循环正在后台启动 server.ksh 调用 (&);这允许循环继续下一次迭代,而 server.ksh 调用仍在处理中;最终结果是您同时进行了多个 ssh 调用。

看起来一切都在同一时间完成,因为 date 命令的默认输出仅精确到最接近的秒。如果提高 date 输出的精度,您可能会看到 ssh 调用未在 'exactly' 同时完成,例如:

# output format: HH:MM:SS.nnnnnnnnn (nano-seconds)
ssh $n "date +'%H:%M:%S.%N'";

很明显(?)如果不同服务器的系统时钟有几分之一秒的偏差,date 输出也可能存在差异。