-1
我想從IP Pool文件中讀取ip並從中獲取whois,然後將其報告給CSV電子表格文件。 我寫這個劇本來執行:舉報whois ip到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的輸出應該被引用。請參閱https://www.shellcheck.net/中的其他幾個指針。 –
我替換了NETNAME =「$(grep netname whoisip)」,但仍然是第二個值爲空! – mbzadegan
'netname'!='NETNAME' – Cyrus