2015-01-29 2 views
0

나는 이것에 새로운이다 그래서 patiant 있으십시오.스크립트에서 동작 로그를 어떻게 얻을 수 있습니까?

필자는 스크립트를 작성하지 않았지만 (그다지 어쩌면 언젠지는 아니 었음) var/logs에 로그를 출력해야합니다.

아무도 도와 주시겠습니까?

모든 작업이 해당 스크립트에서 완료되었음을 알아야합니다. 도움을

#!/bin/bash 
# copy the old database to a timestamped copy 
TIMESTAMP=$(date +%d) 
[email protected] 

# backup Spamassassin bayes db 
sa-learn -p /usr/mailcleaner/etc/mailscanner/spam.assassin.prefs.conf --siteconfigpath /usr/mailcleaner/share/spamassassin --backup >/var/mailcleaner/spool/spamassassin/spamass_rules.bak 
# backup Bogofilter bayes db 
cp -a /root/.bogofilter/wordlist.db "/root/.bogofilter/$TIMESTAMP-wordlist.db" 
if [ -f "/root/.bogofilter/$TIMESTAMP-wordlist.db.gz" ] 
then 
    rm -f "/root/.bogofilter/$TIMESTAMP-wordlist.db.gz" 
fi 
gzip "/root/.bogofilter/$TIMESTAMP-wordlist.db" 

# get the spam and ham from the imap mailbox for the spamassassin and bogofilter db's 
/opt/mailcleaner/scripts/imap-sa-learn.pl 
if [ $? -ne 0 ] 
then 
    (
     echo "Subject: Bogofilter database update $(hostname) failed" 
     ls -l /var/mailcleaner/spool/bogofilter/database/ 
    ) | /usr/sbin/sendmail $REPORT_EMAIL 
    exit 1 
fi 

# copy the database to the right location 
cp /root/.bogofilter/wordlist.db /var/mailcleaner/spool/bogofilter/database/wordlist.db 
# If slave(s) Mailcleaner exists, ssh copy dbs to the slave(s) 
#scp /root/.bogofilter/wordlist.db mailcleaner2.domain.com:/var/mailcleaner/spool/bogofilter/database/ 
#scp /var/mailcleaner/spool/spamassassin/spamass_rules.bak mailcleaner2.domain.com:/var/mailcleaner/spool/spamassassin/ 

# get the spam and ham counts from bogofilter - this just prints how many spam and ham you collected so far... 
/opt/bogofilter/bin/bogoutil -w /var/mailcleaner/spool/bogofilter/database/wordlist.db .MSG_COUNT 

다시 한번 감사 : 여기

는 스크립트입니다.

주권

답변

0

그것은 당신이 스크립트를 실행하면 바로 출력 리디렉션을 사용하는 것이 가장 쉬운 방법 :

./the_script.sh > /var/log/the_script.log 2>&1 

2>&1은 표준 에러 (오류 스트림)뿐만 아니라, 표준 출력 (출력 스트림)를 캡처하는 것입니다. 당신이 콘솔에 출력을 참조 로그 파일을 작성하려면

, tee 사용 : 스크립트는 내가 당신을 그렇게 할 수 할 수있는 방법을 상징적 그렇게 확신하지으로 매일 크론에

./the_script.sh 2>&1 | tee /var/log/the_script.log 
+0

을 pls 조언. – rajbps

+0

crontab에서 쉘 명령을 작성할 수 있습니다. 위와 비슷한 명령 행을 사용하십시오. – Thomas

+0

예를 들어 본다면 위대한 것이 될 것입니다. 제 능력은 매우 제한적이지만 배울 의향이 있습니다. – rajbps

관련 문제