1.根据进程名杀死进程
Shell脚本源码如下:
#!/bin/sh #根据进程名杀死进程 if [ $# -lt 1 ] then echo "缺少参数:procedure_name" exit 1 fi PROCESS=`ps -ef|grep $1|grep -v grep|grep -v PPID|awk '{ print $2}'` for i in $PROCESS do echo "Kill the $1 process [ $i ]" kill -9 $i done
效果截图:
2.使用定时任务
crontab:定时任务的守护进程,精确到分,设计秒的我们一般写脚本 -->相当于闹钟
日志文件: ll /var/log/cron*
编辑文件: vim /etc/crontab
进程:ps -ef | grep crond ==> /etc/init.d/crond restart
作用:定时备份,实时备份
usage: crontab [-u user] file crontab [-u user] [ -e | -l | -r ] (default operation is replace, per 1003.2) -e (edit user's crontab) -l (list user's crontab) -r (delete user's crontab) -i (prompt before deleting user's crontab) -s (selinux context)
crontab -e 编辑定时任务
crontab -l 列出定时任务
3. 查看crontab执行历史记录
grep "script" /var/log/cron
比如,下面的命令就是从/var/log/cron.log 检测cron任务是否有执行脚本文件