shell脚本超时控制
来源:互联网 发布:公安数据恢复 编辑:程序博客网 时间:2024/05/20 08:27
写脚本的时候,经常需要用到超时控制。看《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脚本之场景控制脚本
- WPF DataGrid 常用属性
- lvm分析之简介
- storm开发总结【一】
- javascript声明变量var和this的总结
- 回归windows xp
- shell脚本超时控制
- 语音编码分类及编解码标准
- 正则表达式使用小结 转帖
- 黑马程序员--正则表达式
- 我也想有这种生活节奏!!!
- socket 实现点到点聊天功能
- Lua 语言 15 分钟快速入门
- 【HBase运维系列】集群间的数据拷贝-copytable
- net start 驱动 返回:发生系统错误6 句柄无效