首页 技术 正文
技术 2022年11月19日
0 收藏 417 点赞 3,879 浏览 3143 个字

1.新建/test/killcpu.sh shell脚本 并授予权限0755
#!/bin/bash
ps axf -o “pid %cpu” | awk ‘{if($2>=50.0) print $1}’ | while read procid
do
kill -9 $procid
done

2.安装crontab
yum -y install vixie-cron
3.查看定时任务 crontab -l
4.添加定时任务 crontab -e

分  时  日  月  周  命令
第1列表示分钟1~59 每分钟用*或者 */1表示
第2列表示小时1~23(0表示0点)
第3列表示日期1~31
第4列表示月份1~12
第5列标识号星期0~6(0表示星期天)
第6列要运行的命令
## For excuting killcpu.sh every 3 seconds##on 2017-03-09 每3秒执行脚本
*/1 * * * * /test/killcpu.sh
*/1 * * * * sleep 3 && /test/killcpu.sh
*/1 * * * * sleep 6 && /test/killcpu.sh
*/1 * * * * sleep 9 && /test/killcpu.sh
*/1 * * * * sleep 12 && /test/killcpu.sh
*/1 * * * * sleep 15 && /test/killcpu.sh
*/1 * * * * sleep 18 && /test/killcpu.sh
*/1 * * * * sleep 21 && /test/killcpu.sh
*/1 * * * * sleep 24 && /test/killcpu.sh
*/1 * * * * sleep 27 && /test/killcpu.sh
*/1 * * * * sleep 30 && /test/killcpu.sh
*/1 * * * * sleep 33 && /test/killcpu.sh
*/1 * * * * sleep 36 && /test/killcpu.sh
*/1 * * * * sleep 39 && /test/killcpu.sh
*/1 * * * * sleep 42 && /test/killcpu.sh
*/1 * * * * sleep 45 && /test/killcpu.sh
*/1 * * * * sleep 48 && /test/killcpu.sh
*/1 * * * * sleep 51 && /test/killcpu.sh
*/1 * * * * sleep 54 && /test/killcpu.sh
*/1 * * * * sleep 57 && /test/killcpu.sh
#—————————————————————–

## For excuting killcpu.sh every 1 seconds##on 2017-03-09 每1秒执行脚本
*/1 * * * * /test/killcpu.sh
*/1 * * * * sleep 1 && /test/killcpu.sh
*/1 * * * * sleep 2 && /test/killcpu.sh
*/1 * * * * sleep 3 && /test/killcpu.sh
*/1 * * * * sleep 4 && /test/killcpu.sh
*/1 * * * * sleep 5 && /test/killcpu.sh
*/1 * * * * sleep 6 && /test/killcpu.sh
*/1 * * * * sleep 7 && /test/killcpu.sh
*/1 * * * * sleep 8 && /test/killcpu.sh
*/1 * * * * sleep 9 && /test/killcpu.sh
*/1 * * * * sleep 10 && /test/killcpu.sh
*/1 * * * * sleep 11 && /test/killcpu.sh
*/1 * * * * sleep 12 && /test/killcpu.sh
*/1 * * * * sleep 13 && /test/killcpu.sh
*/1 * * * * sleep 14 && /test/killcpu.sh
*/1 * * * * sleep 15 && /test/killcpu.sh
*/1 * * * * sleep 16 && /test/killcpu.sh
*/1 * * * * sleep 17 && /test/killcpu.sh
*/1 * * * * sleep 18 && /test/killcpu.sh
*/1 * * * * sleep 19 && /test/killcpu.sh
*/1 * * * * sleep 20 && /test/killcpu.sh
*/1 * * * * sleep 21 && /test/killcpu.sh
*/1 * * * * sleep 22 && /test/killcpu.sh
*/1 * * * * sleep 23 && /test/killcpu.sh
*/1 * * * * sleep 24 && /test/killcpu.sh
*/1 * * * * sleep 25 && /test/killcpu.sh
*/1 * * * * sleep 26 && /test/killcpu.sh
*/1 * * * * sleep 27 && /test/killcpu.sh
*/1 * * * * sleep 28 && /test/killcpu.sh
*/1 * * * * sleep 29 && /test/killcpu.sh
*/1 * * * * sleep 30 && /test/killcpu.sh
*/1 * * * * sleep 31 && /test/killcpu.sh
*/1 * * * * sleep 32 && /test/killcpu.sh
*/1 * * * * sleep 33 && /test/killcpu.sh
*/1 * * * * sleep 34 && /test/killcpu.sh
*/1 * * * * sleep 35 && /test/killcpu.sh
*/1 * * * * sleep 36 && /test/killcpu.sh
*/1 * * * * sleep 37 && /test/killcpu.sh
*/1 * * * * sleep 38 && /test/killcpu.sh
*/1 * * * * sleep 39 && /test/killcpu.sh
*/1 * * * * sleep 40 && /test/killcpu.sh
*/1 * * * * sleep 41 && /test/killcpu.sh
*/1 * * * * sleep 42 && /test/killcpu.sh
*/1 * * * * sleep 43 && /test/killcpu.sh
*/1 * * * * sleep 44 && /test/killcpu.sh
*/1 * * * * sleep 45 && /test/killcpu.sh
*/1 * * * * sleep 46 && /test/killcpu.sh
*/1 * * * * sleep 47 && /test/killcpu.sh
*/1 * * * * sleep 48 && /test/killcpu.sh
*/1 * * * * sleep 49 && /test/killcpu.sh
*/1 * * * * sleep 50 && /test/killcpu.sh
*/1 * * * * sleep 51 && /test/killcpu.sh
*/1 * * * * sleep 52 && /test/killcpu.sh
*/1 * * * * sleep 53 && /test/killcpu.sh
*/1 * * * * sleep 54 && /test/killcpu.sh
*/1 * * * * sleep 55 && /test/killcpu.sh
*/1 * * * * sleep 56 && /test/killcpu.sh
*/1 * * * * sleep 57 && /test/killcpu.sh
*/1 * * * * sleep 58 && /test/killcpu.sh
*/1 * * * * sleep 59 && /test/killcpu.sh
#—————————————————————–
5.重启服务 service crond restart
6.添加开机启动 chkconfig –list crond
7.查看开机启动服务 chkconfig

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,036
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,522
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,370
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,151
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,784
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,866