Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 向csv文件报告谁是ip_Bash_Csv_Whois - Fatal编程技术网

Bash 向csv文件报告谁是ip

Bash 向csv文件报告谁是ip,bash,csv,whois,Bash,Csv,Whois,我想从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

我想从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

为什么第二个值为空?

我试图修复您的脚本:

#!/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

“var=”后面不能跟空格。“var=cat whoisip | grep“netname”将尝试将var设置为字符串,而不是grep的输出。例如,请改用NETNAME=“$(grep NETNAME whoisip)”。注意,变量名应该大写,grep的输出应该被引用。有关其他几个指针,请参阅。我替换了NETNAME=“$(grep NETNAME whoisip)”,但第二个值仍然为空<代码>网络名称!=
NETNAME
谢谢大家,我的问题通过shellcheck.net解决了。
#!/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
var=value  #Correct -> var has the value value
var= value #Incorrect -> var is empty