shell timeout
写脚本的时候,经常需要用到超时控制。看《shell专家编程》时看到一个好例:修改了一下,
1.超过timeout时间还没执行完,则kill进程,发邮件告警:
set-x
mailSend()
{
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/null2>&1&& mailSend )&
watchdog=$!
sleeppid=$PPID
wait $commandpid >/dev/null2>&1
kill $sleeppid >/dev/null2>&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/null2>&1
kill -9 $watchdog >/dev/null2>&1
kill $sleeppid >/dev/null2>&1
}
shell timeout的更多相关文章
- python免密远程执行shell
使用paramiko库:https://github.com/paramiko/paramiko 简单封装SSH类 import paramiko class SSH: def __init__(se ...
- child_process小解
js是一种单进程单线程的语言,但现行的cpu都是多核的,为了解决单进程单线程对多核使用不足的问题,child_process应运而生,理想情况下每个进程各自利用一个内核. 主要有四种方法来创建子进程, ...
- MIPCMS V3.1.0 远程写入配置文件Getshell过程分析(附批量getshell脚本)
作者:i春秋作家--F0rmat 0×01 前言 今天翻了下CNVD,看到了一个MIPCMS的远程代码执行漏洞,然后就去官网下载了这个版本的源码研究了下.看下整体的结构,用的是thinkPHP的架 ...
- python 中的queue, deque
python3 deque(双向队列) 创建双向队列 import collections d = collections.deque() append(往右边添加一个元素) import colle ...
- Python的并发并行[3] -> 进程[0] -> subprocess 模块
subprocess 模块 0 模块描述 / Module Description From subprocess module: """Subprocesses wit ...
- zabbix ZBX_NOTSUPPORTED: Timeout while executing a shell script.
有一个监控一直都是正常的,今天突然收到报警邮件,上服务器查看服务又是正常的,但是报警邮件还是没恢复 监控端进行脚本测试,发现是正常的 到监控端使用zabbix_get -s ip -p 端口 -k ...
- 解决zabbix“ZBX_NOTSUPPORTED: Timeout while executing a shell script”报错
如题所示,在zabbix_server使用zabbix_get获取自定义“UserParameter”对应的脚本的数据时,出现了如题所示的报错信息 [root@nmp01 scripts]# /usr ...
- shell中timeout实现
第一种 function timeout() { waitsec=$SLEEP_TIME ( $* ) & pid=$! ( sleep $waitsec && kill -H ...
- Linux shell脚本编程(一)
Linux shell脚本编程: 守护进程,服务进程:启动?开机时自动启动: 交互式进程:shell应用程序 广义:GUI,CLI GUI: CLI: 词法分析:命令,选项,参数 内建命令: 外部命令 ...
随机推荐
- idea+maven
使用IntelliJ IDEA开发SpringMVC网站(一)开发环境 http://my.oschina.net/gaussik/blog/385697 使用IntelliJ IDEA开发Sprin ...
- JavaScript Comparison and Logical Operators
Ref:http://www.w3schools.com/js/js_comparisons.asp var r = 1; var result = r || 2; console.log(resul ...
- [转帖]FPGA--Vivado
来源:http://home.eeworld.com.cn/my/space-uid-639749-blogid-267593.html 一般的,在Verilog中最常用的编码方式有二进制编码(Bin ...
- 关于UNION和UNION ALL的区别
今天在运行程序的时候发现个问题,就是计算和的时候两条数据一样的话自动去除重复的,可是我这个程序需要重复的数据也算进来呀,然后就找原因,最后在sql语句中找到了是union和union all的问题,简 ...
- 项目中常用SQL语句总结
1.项目中常常需要修改字段长度,但需要保留数据--增加业务受理 项目名称 字段长度alter table t_ywsl add aa varchar2(200);update t_ywsl set a ...
- POJ 2112.Optimal Milking (最大流)
时间限制:2s 空间限制:30M 题意: 有K台挤奶机(编号1~K),C头奶牛(编号K+1~K+C),给出各点之间距离.现在要让C头奶牛到挤奶机去挤奶,每台挤奶机只能处理M头奶牛,求使所走路程最远的奶 ...
- Web::Scraper 页面提取分析
一组用来提取HTML文档中元素内容的工具集,它能够理解HTML和CSS选择器以及XPath表达式. 语法 use URI; use Web::Scraper; # First, create your ...
- golang bufio writer,reader 缓存规则
读,写,缓冲区可以杜绝频繁的读,写动作1.写缓存,如果一次write的长度大于buffer长度那么久发送当前缓冲区的内容并且发送要写入的内容,就是不在缓存了.如果发送的内容小于buffer长度,就按缓 ...
- UILongPressGestureRecognizer的selector多次调用解决方法
当你使用longPress gesture recognizer 时,你可能会发现调用了多次. UILongPressGestureRecognizer *longPress = [[UILongPr ...
- centos安装nodejs和mongodb
安装nodejs: Run as root on RHEL, CentOS or Fedora, for Node.js v4 LTS Argon: curl --silent --location ...