2017-03-23 1 views
1

awstats 용 빠른 bash 스크립트. 아름답다는 사실을 알고 있지만 루프가 발생하지 않는 문제가 있습니다. 출력은 name1에 대해 하나의 루프를 수행했음을 보여주고 name2에는 결코 도달하지 않고 printf에는 name3을 사용하지 않습니다.If 문이 올바르게 루핑되지 않는 Bash 루프

#!/bin/bash 

awstats_command='perl /var/www/html/awstats/wwwroot/cgi-bin/awstats.pl' 
html_path="/var/www/html/awstats/wwwroot" 
activelogpath="/logs/web/active" 
archivelogpath="/logs/web/archive" 
day='date +%Y-%m-%d.%H' 

# List of web servers we are processing stats for: 
for i in name1 name2 name3 
do 
     if [[ $i = "name1" ]] 
     then 
       # Custom reports for name1 contains subdirectory statistics 
       printf "\nProcessing log files for $i...\n" 
       /usr/bin/perl /var/www/html/awstats/wwwroot/cgi-bin/awstats.pl -config=name1 -update 
       printf "done.\n" 
       printf "\nGenerating .html files for $i...\n" 
       /var/www/html/awstats/wwwroot/cgi-bin/do.reports $i 
       $awstats_command -config=$i -output=urldetail:/about/ -staticlinks > $html_path/$i/awstats.$i.about.html 
       printf "done.\n" 
     else 
       printf "\nProcessing log files for $i...\n" 
       # Will do something when working $i 
       printf "done.\n" 
       printf "\nGenerating .html files for $i...\n" 
       # Will do something when working $i 
       printf "done.\n" 
     fi 

     printf "\nCompressing and archiving log files...\n" 
     exec /usr/bin/gzip -cv "$activelogpath"/"$i"/*.log > "$archivelogpath"/"$i"/"$(date +%Y%m%d_%H%M%S)".gz 
     # rm -f $activelogpath/$i/*.log 
     printf "\nCompleted!\n" 
done 
+2

'exec'이 원인입니다. 왜 당신은'exec'해야합니까? – codeforester

+1

다음을보십시오 : http://www.shellcheck.net/ – Cyrus

+0

첫 번째 5 줄에서 역 따옴표 (또는'$ (...)')를 사용할 때 작은 따옴표를 사용하고 있습니다. – chepner

답변

1
exec /usr/bin/gzip -cv "$activelogpath"/"$i"/*.log > "$archivelogpath"/"$i"/"$(date +%Y%m%d_%H%M%S)".gz 

exec 명명 된 프로그램으로 현재 프로세스를 대체합니다. 실행은 exec 진술을 지나서 계속되지 않습니다. 여기에는 그럴 필요가 없습니다. 그것 없이는 gzip로 전화하십시오.

gzip -cv "$activelogpath/$i"/*.log > "$archivelogpath/$i/$(date +%Y%m%d_%H%M%S).gz" 

/usr/bin/를 작성하거나 떠나 너무 자주 인용 부호를 다시 입력 할 필요가 없습니다.

관련 문제