【发布时间】:2017-07-15 04:50:49
【问题描述】:
我想从 IP Pool 文件中读取 ip 并从中获取 whois,然后将其报告给 CSV 电子表格文件。 我编写了这个脚本来执行它:
#!/bin/bash
echo "ip,netname,org-name,remarks,descr,country,person,address,phone,origin" > csv
while read -r ip
do
whois $ip > whoisip
netname= cat whoisip | grep "netname"
orgname= cat whoisip | grep "org-name"
remarks= cat whoisip | grep "remarks"
descr= cat whoisip | grep "descr"
country= cat whoisip | grep "Country"
person= cat whoisip | grep "person"
address= cat whoisip | grep "address"
phone= cat whoisip | grep "phone"
origin= cat whoisip | grep "origin"
echo $ip,$netname,$orgname,$remarks,$descr,$country,$person,$address,$phone,$origin >> csv
done <pool
但是,我的脚本会生成这个 CSV 文件:
ip,netname,org-name,remarks,descr,country,person,address,phone,origin
x.x.x.x,,,,,,,,
y.y.y.y,,,,,,,,
z.z.z.z,,,,,,,,
...
为什么第二个值是空的?
【问题讨论】:
-
"var=" 后面不能有空格。 'var=cat whoisip | grep "netname"' 将 尝试 将 var 设置为字符串,而不是 grep 的输出。例如,使用 NETNAME="$(grep netname whoisip)"。请注意,变量名称应大写,并且应引用 grep 的输出。有关其他几个指针,请参阅 shellcheck.net。
-
我替换了 NETNAME="$(grep netname whoisip)" 但第二个值仍然是空的!
-
netname!=NETNAME -
谢谢大家,shellcheck.net 解决了我的问题。