2014-10-07 4 views
0

저는이 문제로 몇 시간의 작업 후에 알아낼 수없는 문제가 있습니다. 이 스크립트는 최종 열에 아무것도 반환 할 수 없습니다.Bash 스크립트 - 열/변수를 반환하지 않습니다.

#!/bin/bash 
file="/Users/USER12/Desktop/url-list.txt" 
log="/Users/USER12/Desktop/url-results.txt" 
fmt="%-25s%-12s%-16s%-20s\n" 
printf "$fmt" DOMAIN_NAME HTTP_CODE RESPONSE_TIME CONTENT_CHECK > "$log" 
while read line 
do 
    read code time < <(curl -o /dev/null --silent --head --write-out '%{http_code} %{time_total}' "$line") 
    curl "$line" 2>/dev/null > /Users/USER12/Desktop/domainQueryString_output.txt 
    ifStatementConditional=`grep "THE CONTENT I'M LOOKING TO VERIFY" /Users/USER12/Desktop/domainQueryString_output.txt | wc -l` 
    if [ $ifStatementConditional -eq 1 ] ; then 
      second_check="online" 
     else 
      second_check="DOMAIN IS OFFLINE" 
    fi 
printf "$fmt" "$line" "$code" "$time" "$second_chance" >> "$log" 
done <"$file" 

은 다음하지만 마지막 열까지 아무것도 .... 도움말들에 대한

DOMAIN_NAME    HTTP_CODE RESPONSE_TIME CONTENT_CHECK  
google.com    301   1.177        

감사를 반환하지 않습니다. 도움말은 많이 감사합니다.

+2

당신은 "$의 second_check"를 했어야 "$의 second_chance"가. – PSkocik

+0

하하. 나는 그걸 비웃을 수있다. 많이 감사합니다 @ PSkocik – aLee788

+0

문제는 없습니다. 사람들은 이보다 훨씬 더 멍청한 코드로 여기에옵니다. 나는 지금 머리 부상에서 사실상 회복하고 있고, 여기에서 약간의 질문을 읽는 것은 나를 매우 혼자가 아닌 것으로 느끼게한다. :디 – PSkocik

답변

2

"$ second_check"가 있어야하는 곳에 "$ second_chance"가 있습니다. 다른 그 다음은 if 확인을 할 수있는 더 좋은 방법입니다

if grep "THE CONTENT I'M LOOKING TO VERIFY" $yourfile -q 
then 
    ... 
else 
    ... 
fi 
관련 문제