我想从IP池文件中读取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,,,,,,,,
...
为什么第二个值为空?
答案 0 :(得分:0)
我试图修复你的脚本:
#!/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 -i "netname"`
orgname=`cat whoisip | grep -i "org-name"`
remarks=`cat whoisip | grep -i "remarks"`
descr=`cat whoisip | grep -i "descr"`
country=`cat whoisip | grep -i "Country"`
person=`cat whoisip | grep -i "person"`
address=`cat whoisip | grep -i "address"`
phone=`cat whoisip | grep -i "phone"`
origin=`cat whoisip | grep -i "origin"`
echo $ip,$netname,$orgname,$remarks,$descr,$country,$person,$address,$phone,$origin >> csv
done <pool
``
执行随附的commando并返回输出
-i
使grep不区分大小写
在变量名称,等号和变量声明和/或赋值中,不允许空格:
var=value #Correct -> var has the value value
var= value #Incorrect -> var is empty