Shell Programming Basics-sendmail

Source: Internet
Author: User
Tags disk usage

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.