Installation of the Linux SendEmail tool 1. Download the file #wget http://files.cnblogs.com/files/sunziying/sendEmail-v1.56.tar.gz2. Installing #yum Install SENDEMAIL3, main parameters:-F is the From, the sender address-t means to, the recipient address-SSendermail server domain-u topic-xuSenderUser name (before @)-XPSenderUser password-M plain text information-o message-file=/root/. Send the contents of a file-a send an attachment (-m,-o,-a can be used simultaneously) 4, instance: Sendemail-u test-f $mail _f-t $mail _to_list-s $mail _smtp-xu $mail _user-xp $mail _pwd-o $mail _type message-charset=utf-8 message-file=${tmpfile} variables are referenced below: Export mail_to_list= ' [email Protected],[email protected] ' export mail_f= ' [email protected] ' export mail_smtp= ' smtp.163.com ' export Mail_user= ' Sunzy ' export mail_pwd= ' * * * * * * mail_type= ' message-content-type=html ' 5. Example: Monitor disk usage under Linux and send alert messages automatically after thresholds are exceeded. Cases:
#!/bin/bashpartition_list= (' df-h | awk ' Nf>3&&nr>1{sub (/%/, "", $ (NF-1));p rint $NF, $ (NF-1)} ") Notification_email () { emailuser= ' [email protected] ' emailpasswd= ' * * * * * * * * emailsmtp= ' smtp.163.com ' sendto= ' [email protected] ' title= ' Disk Space Alarm ' /usr/sbin/sendmail-f $emailuser-T $sendto-S $ Emailsmtp-u $title-xu $emailuser-xp $emailpasswd}critical=80crit_info= "" for (i=0;i<${#partition_list [@]};i+=2] Do if ["${partition_list[(i+1)]}"-lt "$critical"];then echo "ok! ${partition_list[i]} used ${partition_list[((i+1))]}% " else If [" ${partition_list[((i+1))]} "-GT" $critical "];then crit_info= $crit _info" Warning!!! ${partition_list[i]} used ${partition_list[((i+1))]}%\n " fi Fidoneif ["$crit _info"! = ""];then echo-e $crit _info | Notification_emailfi
Shell Programming Basics-sendmail