0%

mailx 发送邮件小计

安装postfix服务

yum install postfix
/etc/init.d/postfix start
chkconfig postfix on

发送格式

mailx -s subject user@xxx.com < message_file
echo “内容” | mailx -s “邮件标题” user@xxx.com

其他选项

-r 指定发件人
-c 指定抄送人
-b 指定密送人
多个收件人使用逗号分隔
有些邮箱(如qq邮箱)会当成垃圾邮件拦截,日志中可以看到500错误

监控服务脚本是否运行正常

监控脚本内容

1
2
3
4
5
6
#!/bin/bash
count=`ssh m1 ps -ef|grep real_wrf.csh |grep -v "grep" |wc -l`
#echo $count
if [ 0 == $count ];then
mailx -s "the real_wrf.csh is not running " a1@xxx.com.cn,a2@xxx.com.cn < t.txt
fi

监测目录下是否有文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/bin/bash
#每天6:00~7:00检查前一天00时的数据,每天16:00~18:00检查前一天12时的数据

Date1=`date -d "1 day ago" +"%Y%m%d00"`
Date2=`date -d "1 day ago" +"%Y%m%d_06"`
file="\
/data/Model3/WRF/data/output/wrf/$Date1/wrfout_d03 \
/data/Model3/CMAQ4.7/data/cctm-wrf/$Date1/CCTM_CONC.cn03.*.ncf \
/data/Model3/CAMx6/data/post_save/$Date1/camxsave_d03* \
/data/em/result/predictions/SHAANXI/$Date2/POST/naqpms_d03.* \
/data/Model3/WRF/data/output/wrfchem/$Date1/wrfout_d03* \
"
for i in $file
do
if [ ! -f "$i" ]; then
echo "$i 文件不存在" >> check_00mx_$Date1.txt
mailx -s "00时文件数据模型数据不存在" b@xx.com.cn < check_00mx_$Date1.txt
fi
done

监测目录是否存在,目录是否为空

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/bash
#每天6:00~7:00检查前一天00时的数据,每天16:00~18:00检查前一天12时的数据

Date1=`date +"%Y"`
Date2=`date +"%m"`
Date3=`date -d '-1 day' +"%d"`
Date4=`date +"%Y%m%d00"`
Dir=/data/Model3/WeatherForecast
WRF_Dir="$Dir/WRF/$Date1/$Date2/$Date3/d3/500/ \
$Dir/WRF/$Date1/$Date2/$Date3/d3/700/ \
$Dir/WRF/$Date1/$Date2/$Date3/d3/850/ \
$Dir/WRF/$Date1/$Date2/$Date3/d3/srf/"

WRFCHEM_Dir="$Dir/WRFCHEM/$Date1/$Date2/$Date3/00/d3/aqi \
$Dir/WRFCHEM/$Date1/$Date2/$Date3/00/d3/co \
$Dir/WRFCHEM/$Date1/$Date2/$Date3/00/d3/no2 \
$Dir/WRFCHEM/$Date1/$Date2/$Date3/00/d3/o3 \
$Dir/WRFCHEM/$Date1/$Date2/$Date3/00/d3/pm10 \
$Dir/WRFCHEM/$Date1/$Date2/$Date3/00/d3/pm25 \
$Dir/WRFCHEM/$Date1/$Date2/$Date3/00/d3/so2"

WRFCHEMDAY_Dir="$Dir/WRFCHEMDAY/$Date1/$Date2/$Date3/00/d3/aqi \
$Dir/WRFCHEMDAY/$Date1/$Date2/$Date3/00/d3/co \
$Dir/WRFCHEMDAY/$Date1/$Date2/$Date3/00/d3/no2 \
$Dir/WRFCHEMDAY/$Date1/$Date2/$Date3/00/d3/o3 \
$Dir/WRFCHEMDAY/$Date1/$Date2/$Date3/00/d3/pm10 \
$Dir/WRFCHEMDAY/$Date1/$Date2/$Date3/00/d3/pm25 \
$Dir/WRFCHEMDAY/$Date1/$Date2/$Date3/00/d3/so2"

CAMX_Dir="$Dir/CAMX/$Date1/$Date2/$Date3/00/d3/aqi \
$Dir/CAMX/$Date1/$Date2/$Date3/00/d3/co \
$Dir/CAMX/$Date1/$Date2/$Date3/00/d3/no2 \
$Dir/CAMX/$Date1/$Date2/$Date3/00/d3/o3 \
$Dir/CAMX/$Date1/$Date2/$Date3/00/d3/pm10 \
$Dir/CAMX/$Date1/$Date2/$Date3/00/d3/pm25 \
$Dir/CAMX/$Date1/$Date2/$Date3/00/d3/so2 "

CAMxDAY_Dir="$Dir/CAMxDAY/$Date1/$Date2/$Date3/00/d3/aqi \
$Dir/CAMxDAY/$Date1/$Date2/$Date3/00/d3/co \
$Dir/CAMxDAY/$Date1/$Date2/$Date3/00/d3/no2 \
$Dir/CAMxDAY/$Date1/$Date2/$Date3/00/d3/o3 \
$Dir/CAMxDAY/$Date1/$Date2/$Date3/00/d3/pm10 \
$Dir/CAMxDAY/$Date1/$Date2/$Date3/00/d3/pm25 \
$Dir/CAMxDAY/$Date1/$Date2/$Date3/00/d3/so2 "

CMAQ_WRF_Dir="$Dir/CMAQ.WRF/$Date1/$Date2/$Date3/00/d3/aqi \
$Dir/CMAQ.WRF/$Date1/$Date2/$Date3/00/d3/co \
$Dir/CMAQ.WRF/$Date1/$Date2/$Date3/00/d3/no2 \
$Dir/CMAQ.WRF/$Date1/$Date2/$Date3/00/d3/o3 \
$Dir/CMAQ.WRF/$Date1/$Date2/$Date3/00/d3/pm10 \
$Dir/CMAQ.WRF/$Date1/$Date2/$Date3/00/d3/pm25 \
$Dir/CMAQ.WRF/$Date1/$Date2/$Date3/00/d3/so2 "

CMAQDAY_Dir="$Dir/CMAQDAY/$Date1/$Date2/$Date3/00/d3/aqi \
$Dir/CMAQDAY/$Date1/$Date2/$Date3/00/d3/co \
$Dir/CMAQDAY/$Date1/$Date2/$Date3/00/d3/no2 \
$Dir/CMAQDAY/$Date1/$Date2/$Date3/00/d3/o3 \
$Dir/CMAQDAY/$Date1/$Date2/$Date3/00/d3/pm10 \
$Dir/CMAQDAY/$Date1/$Date2/$Date3/00/d3/pm25 \
$Dir/CMAQDAY/$Date1/$Date2/$Date3/00/d3/so2 "

NAQMPS_Dir="$Dir/NAQMPS/$Date1/$Date2/$Date3/00/d3/aqi \
$Dir/NAQMPS/$Date1/$Date2/$Date3/00/d3/co \
$Dir/NAQMPS/$Date1/$Date2/$Date3/00/d3/no2 \
$Dir/NAQMPS/$Date1/$Date2/$Date3/00/d3/o3 \
$Dir/NAQMPS/$Date1/$Date2/$Date3/00/d3/pm10 \
$Dir/NAQMPS/$Date1/$Date2/$Date3/00/d3/pm25 \
$Dir/NAQMPS/$Date1/$Date2/$Date3/00/d3/so2 "

NAQMPSDAY_Dir="$Dir/NAQMPSDAY/$Date1/$Date2/$Date3/00/d3/aqi \
$Dir/NAQMPSDAY/$Date1/$Date2/$Date3/00/d3/co \
$Dir/NAQMPSDAY/$Date1/$Date2/$Date3/00/d3/no2 \
$Dir/NAQMPSDAY/$Date1/$Date2/$Date3/00/d3/o3 \
$Dir/NAQMPSDAY/$Date1/$Date2/$Date3/00/d3/pm10 \
$Dir/NAQMPSDAY/$Date1/$Date2/$Date3/00/d3/pm25 \
$Dir/NAQMPSDAY/$Date1/$Date2/$Date3/00/d3/so2 "

Dir2="$WRF_Dir $WRFCHEM_Dir $WRFCHEMDAY_Dir $CAMX_Dir $CAMxDAY_Dir $CMAQ_WRF_Dir $CMAQDAY_Dir $NAQMPS_Dir $NAQMPSDAY_Dir"
for d in $Dir2
do
if [ ! -d $d ]; then
echo "$d 目录不存在" >> /tmp/check_00tp_$Date4.txt
elif [ `ls $d |wc -l` -eq 0 ]; then
echo "$d 目录下文件不存在" >> /tmp/check_00tp_$Date4.txt
fi
done
mailx -s "$Date4 00时 模型出图情况" c@xx.com.cn < /tmp/check_00tp_$Date4.txt

设置crontab

1
2
3
01 13,17,01,04 * * * /data/tool/DRAW/shell/check_status/check_wrf.sh
01 07 * * * /data/tool/DRAW/shell/check_status/check_00mx.sh
01 08 * * * /data/tool/DRAW/shell/check_status/check_00tp.sh

另附短信发送脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#!/bin/bash
datedir1=`date +%Y%d`
datedir2=`date +%Y%d%y`
un="xxxxxxxx"
pw="xxxxxxxxxx"
phone="xxxxxxxxxxx"
msg="this is a test mes,please ignore"

if [ ! -d "/data/em/data/GFS/$datedir1/$datedir2" ];then
curl --data "un=$un&pw=$pw&phone=$phone&msg=$msg&rd=1" "http://sms.253.com/msg/send"
echo -e "\n query balance:"
curl --data "un=$un&pw=$pw" "http://sms.253.com/msg/balance"
fi
echo "send sms:"

短信参考:https://www.253.com/api-docs-13.html