2017-03-23 59 views
1

awstats用のクイックbashスクリプト。美しいとは言えますが、ループに問題はありません。出力はname1に対して1つのループを実行したことを示しているだけで、printfでname2、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/を書くために、またはそれほど頻繁に引用符を残して再入力する必要もありません。

関連する問題