shell编程基础-sendmail
Posted sunziying
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了shell编程基础-sendmail相关的知识,希望对你有一定的参考价值。
[root@li229-122 scripts]# sendEmail --help sendEmail-1.56 by Brandon Zehm <caspian@dotconf.net> Synopsis: sendEmail -f ADDRESS [options] Required: -f ADDRESS from (sender) email address(发送人邮箱) * At least one recipient required via -t, -cc, or -bcc * Message body required via -m, STDIN, or -o message-file=FILE Common: -t ADDRESS [ADDR ...] to email address(es)(接收人邮箱) -u SUBJECT message subject(主题) -m MESSAGE message body(正文) -s SERVER[:PORT] smtp mail relay, default is localhost:25(发件人邮箱的SMTP服务器) Optional: -a FILE [FILE ...] file attachment(s)(附件) -cc ADDRESS [ADDR ...] cc email address(es) -bcc ADDRESS [ADDR ...] bcc email address(es) -xu USERNAME username for SMTP authentication(发件人邮箱的用户名) -xp PASSWORD password for SMTP authentication(发件人邮箱的密码) Paranormal: -b BINDADDR[:PORT] local host bind address -l LOGFILE log to the specified file -v verbosity, use multiple times for greater effect -q be quiet (i.e. no STDOUT output) -o NAME=VALUE advanced options, for details try: --help misc -o message-content-type=<auto|text|html> -o message-file=FILE -o message-format=raw -o message-header=HEADER -o message-charset=CHARSET -o reply-to=ADDRESS -o timeout=SECONDS -o username=USERNAME -o password=PASSWORD -o tls=<auto|yes|no> -o fqdn=FQDN Help: --help the helpful overview you\'re reading now --help addressing explain addressing and related options --help message explain message body input and related options --help networking explain -s, -b, etc --help output explain logging and other output options --help misc explain -o options, TLS, SMTP auth, and more
#!/bin/bash
partition_list=(`df -h | awk \'NF>3&&NR>1{sub(/%/,"",$(NF-1));print $NF,$(NF-1)}\'`)
notification_email()
{
emailfrom=\'sunzy@163.com\'
sendto=\'7589457343@qq.com\'
emailsmtp=\'smtp.163.com\'
title=\'Disk Space Alarm\'
emailuser=\'sunzy@163.com\'
emailpasswd=\'*****\'
/usr/sbin/sendmail -f $emailfrom -t $sendto -s $emailsmtp -u $title -xu $emailuser -xp $emailpasswd
}
critical=80
crit_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"
echo -e $crit_info | notification_email
fi
done
以上是关于shell编程基础-sendmail的主要内容,如果未能解决你的问题,请参考以下文章