linux - Bash Shell While inside for loop not working-只选择第一个值
问题描述
我在 for 循环中运行一个简单的 while 循环,下面是我的代码。我的问题是在运行此代码时,while 循环仅从文件 iplist.txt 中选择第一行。
需要了解为什么我的 while 循环没有为整个文件逐行运行。
for node in `nodeset -e @nishant1`;
do
while read -r q; do
nslookup $q | grep uhc |awk '{print $4}' >/tmp/nslookup.txt
dest=`cat /tmp/nslookup.txt`
clush -w $node "sh /opt/OV/qa-ira/ira/bin/ira setProbe ICMP -on BDPassS -op icmpEcho -ta $q -tn ICMP_'$node'_'$dest' -tt IPv4 -ds 256"
done< /iplist.txt
done
解决方案
该命令很可能clush
也从中读取,stdin
因此它消耗了文件中的所有其他行。所以试试这样:
#
# prevent clush from reading current stdin
#
clush -w $node ... < /dev/null
推荐阅读
- mysql - MySQL SELECT 行如果不存在或如果存在做条件
- typescript - 通用对象中键的 TypeGuard 函数
- powershell - MailKit - 通过 PowerShell 发送电子邮件
- eclipse - 在 Eclipse 中检查变量
- python - 计数奇偶数功能
- tableau-desktop - 如何使用 Dateparse 函数创建一年到一年的日期范围,即 2020-2021
- sql - 如何在选定的字符串中查找数字?
- python - Python 类变量在使用插槽时会覆盖所有实例变量 - 为什么?
- sql - 使用 PostgreSQL PL/pgSQL 在 For 循环中添加月份
- ios - 为什么点击键盘时iOS应用程序崩溃?