2013-01-18 1 views
1

SMTP 연결을 사용하여 자동으로 메일을 보내도록 스크립트를 작성했지만 스크립트를 실행하면 가끔 작동하고 때로는 메일을 보내지 않습니다. 행동은 아주 애매합니다.셸 스크립트가 SMTP 서버를 사용하여 정확하게 메일을 보내지 못함

Environment : Linux Server Fedora 14 
Mailing Client : Lotus Notes 8.5.2 

아래 스크립트를 참조하십시오.

# Function for sending email 
sendemail(){ 
date=`date '+%d-%m-%Y'` 
dbDir=/var/lib/MYSQLBACKUP/$date 
dbname='DBNAME' 
log_file="${dbDir}/${dbname}_${date}.log" 
attached_file="${dbname}_${date}.log" 
echo $log_file 
echo $attached_file 
encoded_log_file=`cat $log_file | openssl base64` 
#echo $encoded_log_file 
(echo open 172.40.201.31 25 
sleep 8 
echo helo 172.40.201.31 
echo mail from:[email protected] 
echo rcpt to:[email protected] 
echo data 
echo to:[email protected] 
echo from:[email protected] 
echo "subject: SPARC CQ DB Backup Report : $date :" 
echo "MIME-Version: 1.0" 
#echo "Content-Type: text/plain; charset=UTF-8" 
#echo "Please view attached file" 
echo "Content-Type: text/x-log;name="$attached_file"" 
echo "Content-Disposition:attachment;filename="$attached_file"" 
echo "Content-Transfer-Encoding: base64" 
echo $encoded_log_file 
echo $1 
sleep 15 
echo . 
echo ^] 
echo quit) | telnet 
echo "status:$?" 
echo "Hello done" 
} 

sendemail 
+0

bass-ackwards 날짜 형식은 무엇입니까? – tripleee

+0

"메일 링 클라이언트 : Lotus Notes 8.5.2"의 의미는 무엇입니까? 내가 알 수있는 한, "Mailing Client : ad-hoc shell script"가 있습니까? – tripleee

+0

메일 클라이언트를 사용하지 않으므로 Lotus Notes 용 태그를 제거합니다. 172.40.201.35에서 SMTP 서비스를 제공하는 서버가 Lotus Domino이고 실제로 발생하는 문제가 서버로 인해 발생했다고 생각할 수 있습니다 (즉, 다른 SMTP 서버를 사용하는 경우) 잘 작동하거나 서버가 오류 메시지 등을 생성하는 경우), Lotus-Domino –

답변

0

여기는 /usr/lib/sendmail을 사용하여 다시 작성합니다. 이것은 반드시 시스템의 올바른 위치는 아니지만이를 적용 할 수 있어야합니다.

# Function for sending email 
sendemail(){ 
    date=$(date '+%d-%m-%Y')      # prefer $(...) over `...` 
    dbDir=/var/lib/MYSQLBACKUP/$date 
    dbname='DBNAME' 
    log_file="${dbDir}/${dbname}_${date}.log" 
    attached_file="${dbname}_${date}.log" 
    echo $log_file 
    echo $attached_file 
    encoded_log_file=$(openssl base64 < "$log_file") # notice UUCA fix + quoting 
    #echo $encoded_log_file 
    # You should configure sendmail to use 172.40.201.31 as your smarthost 
    /usr/lib/sendmail -oi -t <<________HERE 
to: [email protected] 
from: [email protected] 
subject: SPARC CQ DB Backup Report : $date : 
MIME-Version: 1.0 
Content-Type: text/x-log; name="$attached_file" 
Content-Disposition: attachment; filename="$attached_file" 
Content-Transfer-Encoding: base64 
X-Ample: notice empty line between headers and body! # <-- look 

$encoded_log_file 
$1 
________HERE 
    echo "status:$?" 
    echo "Hello done" 
} 

sendemail 
+0

친절한 도움에 감사드립니다. – user1409935

0

나는 쉘 스크립트에서 SMTP를 구현하기 위해 노력하는 대신에 메일을 보낼 라이브러리 또는 명령 줄 프로그램 (mail 또는 mailx 등)의 사용을 권장합니다.

+0

으로 다시 태그 할 수 있습니다. 쉘 스크립트가 그렇게 나쁘지는 않지만'telnet' 으로의 파이프 연결은 특히 잘못 될 수 있습니다. 이 작업에는 적합하지 않습니다. – tripleee

관련 문제