【问题标题】:How to search for multiple domain names availability using bash?如何使用 bash 搜索多个域名可用性?
【发布时间】:2021-03-01 19:41:49
【问题描述】:

我正在尝试使用此脚本搜索多个可用域名,但它不起作用,哪里出错了?谢谢

#!/bin/bash 

WEB=('madmane1' 'madmane2' 'madmane3' 'madmane4' 'madmane5' 'madmane6' 'madmane7' 'madmane8' 'madmane9')
 
ELEMENTS=${#WEB[@]} 
 
for (( i=0;i<$ELEMENTS;i++)); do 
      whois ${WEB[${i}]}$'.com' | egrep -q \ 
      '^No match|^NOT FOUND|^Not fo|AVAILABLE|^No Data Fou|has not been regi|No entri' 
      if [ $? -eq 0 ]; then 
          echo "${WEB[${i}]}$'.com' : available" 
      fi 
done 

这是错误:

line 9: ^No match|^NOT FOUND|^Not fo|AVAILABLE|^No Data Fou|has not been regi|No entri: command not found

【问题讨论】:

    标签: linux bash shell scripting


    【解决方案1】:

    将内容分配给数组,然后通过将其分配给不带引号的字符串来破坏它似乎是这里的主要错误,尽管这不是您遇到语法错误的原因。

    你还想避免testing ”$?” to see if a command succeeded or not, an anti-pattern

    另见Correct Bash and shell script variable capitalization

    错误消息的原因似乎是反斜杠后的空格,因此您正在转义空格而不是换行符,因此 shell(在某种意义上正确)将下一行解析为新命令。

    #!/bin/bash 
    
    web=('madmane1' 'madmane2' 'madmane3' 'madmane4' 'madmane5' 'madmane6' 'madmane7' 'madmane8' 'madmane9')
     
    for domain in "${web[@]}"; do
        if whois "$domain.com" |
            grep -Eq '^No match|^NOT FOUND|^Not fo|AVAILABLE|^No Data Fou|has not been regi|No entri' 
        then 
            echo "$domain.com: available" 
        fi 
    done
    

    接下来,在寻求人工帮助之前,可能先尝试http://shellcheck.net/

    【讨论】:

      【解决方案2】:

      我想我解决了https://www.shellcheck.net/ 的问题 现在就在这里:

      #!/bin/bash 
      
      WEB=('madmane1' 'madmane2' 'madmane3' 'madmane4' 'madmane5' 'madmane6' 'madmane7' 'madmane8' 'madmane9')
       
      ELEMENTS=${#WEB[@]} 
       
      for (( i=0;i<$ELEMENTS;i++)); do 
            whois "${WEB[${i}]}"$'.com' | grep -E \
            '^No match|^NOT FOUND|^Not fo|AVAILABLE|^No Data Fou|has not been regi|No entri' 
            if [ $? -eq 0 ]; then 
                echo "${WEB[${i}]}$'.com' : available" 
            fi 
      done 
      

      【讨论】:

      • 您将-q 选项删除为grep,所以这会很吵。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-10
      • 2023-01-14
      • 1970-01-01
      • 1970-01-01
      • 2016-07-30
      • 2018-08-17
      相关资源
      最近更新 更多