unix shell 监控文件夹发送邮件

根据需求监控某些文件夹下是否生成文件,定时任务执行。
由于UNIX系统使用 Bourne Shell 所以和Linux系统shell命令稍有不同:

#!/bin/sh
arr[0]="/app_inter/production/inbound/I02"
arr[1]="/app_inter/production/inbound/AP2POMS"
arr[2]="/app_inter/production/inbound/BS"
arr[3]="/app_inter/production/inbound/I02R"
arr[4]="/app_inter/production/inbound/KPI_AP2POMSD"
arr[5]="/app_inter/production/inbound/KPI_AP2POMSM"

for i in 0 1 2 3 4 5;
do 
if [ "`ls -A ${arr[$i]}`" = "" ]; then
res[$i]="${arr[$i]} : is empty"
else
res[$i]="${arr[$i]} : is not empty"
fi
done

/usr/sbin/sendmail -t test@qq.com<<EOF
To: test@qq.com
Subject: testing
`date "+%Y-%m-%d %H:%M:%S"` :
${res[0]}
${res[1]}
${res[2]}
${res[3]}
${res[4]}
${res[5]}
EOF
    原文作者:lhxsir
    原文地址: https://blog.csdn.net/lhxsir/article/details/82423945
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞