shell脚本超时控制
来源:互联网 发布:dnf老是网络中断 编辑:程序博客网 时间:2024/05/20 10:21
写脚本的时候,经常需要用到超时控制。看《shell专家编程》时看到一个好例:修改了一下,
1.超过timeout时间还没执行完,则kill进程,发邮件告警:
set -xmailSend(){ mailContent="xxxx Web response time over 5 seconds" echo $mailContent | mail -s "xxxxxx Web TimeOut" xxxxx@xxx.cion}timeout(){ waitfor=3 command=$* $command & commandpid=$! ( sleep $waitfor ; kill -9 $commandpid > /dev/null 2>&1 && mailSend ) & watchdog=$! sleeppid=$PPID wait $commandpid > /dev/null 2>&1 kill $sleeppid > /dev/null 2>&1}#测试的函数test123(){ sleep 20}timeout test123
2.超过timeout时间还没执行完,只发邮件告警,程序正常执行:
mailSend(){ mailContent="xxxxe Web response time over 5 seconds,Please have a check !" echo $mailContent | mail -s "xxxxx WEB response time over 5 senconds" $mailTo}timeout(){ waitfor=6 command=$* $command & commandpid=$! ( sleep $waitfor ; mailSend ) & watchdog=$! sleeppid=$PPID wait $commandpid > /dev/null 2>&1 kill -9 $watchdog > /dev/null 2>&1 kill $sleeppid > /dev/null 2>&1}
- shell脚本超时控制
- shell脚本超时控制
- shell脚本超时控制
- Java执行Shell脚本超时控制
- shell脚本超时watchdog
- SHELL脚本-OMC超时补报
- shell脚本逻辑控制
- shell 脚本并发控制
- Shell脚本控制语句
- shell脚本流程控制
- linux shell 脚本/命令 超时 结束
- 执行脚本实现超时时间控制 ---Process
- Shell脚本结构流程控制
- Shell脚本的控制语句
- shell脚本和流程控制
- 通过web控制Shell脚本
- shell系列------控制另一个shell的脚本
- Shell脚本之场景控制脚本
- HDU 4267 A Simple Problem with Integers
- XCode安装cocos2d-x 2.x模板失败解决方法
- 一起来学OpenMP(9)——线程同步之事件同步机制
- Jquery UI学习笔记(1)
- Magento常用Mage::静态方法
- shell脚本超时控制
- 写给即将入行的 程序员 的一封信
- Java hashcode 与 equals 的关系
- Jquery UI学习笔记(2)
- 关于内存溢出
- SGS(三国杀)用java编写-java bean
- RTSP客户端学习(一)——live555库的移植和验证
- 【虚拟化实战】容灾设计之三Stretched Cluster
- win32多线程程序设计笔记(第三章)