Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1384282
  • 博文数量: 254
  • 博客积分: 4173
  • 博客等级: 中校
  • 技术积分: 3400
  • 用 户 组: 普通用户
  • 注册时间: 2011-03-03 21:24
个人简介

不为失败找借口,只为成功找方法!

文章分类

全部博文(254)

文章存档

2021年(3)

2020年(1)

2019年(2)

2017年(10)

2016年(6)

2015年(19)

2014年(24)

2013年(19)

2012年(52)

2011年(118)

分类: Python/Ruby

2013-06-15 17:58:32

原文地址:自动发邮件通知脚本 作者:linux_kaige


1.当有人更新排期表,服务器自动发邮件通知相关人员查看排气表,脚本如下:
  1. [root@admin dpi]# cat email-paiqi.sh
  2. #!/bin/bash
  3. newfile=`find /yk/dpipaiqi/ -type f -cmin -10`
  4. #newfile=/yk/yachi.txt
  5. ttime=`date +%F`
  6. if [  -e "$newfile" ];then
  7. #echo "$newfile" >/yk/dpi/email-content
  8. echo -e "您好:\n\n请查收新的排期表,链接为:ftp://paiqibiao:123456@*.132/${newfile##*/} \n\n谢谢!" >/yk/dpi/email-content
  9. #ftp://paiqibiao:123456@*.132/yk/dpipaiqi/vsftpd.conf
  10. #mail -s '有新的排期表更新' 28*078@qq.com xichubawangaini@163.com
  11. mail -s "DPI new schedule ${ttime}" 28*78@qq.com xichubawangaini@163.com  
  12. #mail -s 'DPI new schedule ${ttime}' 28*078@qq.com xichubawangaini@163.com  
  13. else 
  14. exit 0
  15. fi
  16. [root@admin dpi]#
  17. [root@admin dpi]#echo $LANG
  18. zh_CN.UTF-8
  19. [root@admin dpi]#
2.注意:将脚本写入crontab:
  1. 00 00 * * * /root/cut-log.sh 2>&1 >/dev/null &
  2. */5 * * * * cacti php /var/www/html/nick/poller.php > /dev/null 2>&1
  3. */8 * * * * /yk/dpi/email_paiqi.sh
或者脚本外面加入一个for循环,转入后台执行。执行脚本的用户,得有find newfile的权限,email-content的权限,脚本文件的权限。邮件的subject为中文时,却出现乱码,是编码的问题,暂时还没解决,因为不能随便修改服务器编码,机器上还有其他的服务,以免出现意想不到的问题。如图:
3.放10分钟内多更新排气表则生成的链接会有问题,解决方法:文件扫描时间间隔为10分钟,即不能在10分钟之内更新多次排期表,如果上传错误要立即更新排期表,则将错误的文件删除再上传。
4.乱码问题,最终还是得解决,在我qq邮箱就是好的,163也是好的,就189邮箱还不行,但是客户用的是189邮箱,无奈,用笨的方法,编辑好txt,通过ftp上传上去,然后cp,再追加链接,测试成功,脚本如下:
  1. [yangkai@admin dpi]$ cat email-paiqi.sh
  2. #!/bin/bash
  3. newfile=`find /yk/dpipaiqi/ -type f -cmin -10`
  4. ttime=`date +%F`
  5. if [ -e "$newfile" ];then
  6. cat /yk/dpi/youjianhuifu.txt >/yk/dpi/temp
  7. echo "ftp://paiqibiao:123456@6#.132/${newfile##*/}" >>/yk/dpi/temp
  8. echo "thanks!">>/yk/dpi/temp
  9. mail -s "DPI new schedule ${ttime}" 115#97@qq.com li#89.cn 282#qq.com xichubawangaini@163.com
  10. else
  11. exit 0
  12. fi
  13. [yangkai@admin dpi]$
  14. youjianhuifu.txt: COM executable for DOS
  15. [root@admin dpi]# file temp 
  16. temp: COM executable for DOS
  17. [root@admin dpi]# 







阅读(5968) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~