10

CentOS创建自动执行脚本

 3 years ago
source link: https://www.wencst.com/archives/328
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

CentOS创建自动执行脚本

作者: wencst 分类: linux,Uncategorized 发布时间: 2016-09-30 10:51 阅读: 1,814 次

创建一个可以正常执行的脚本/home/dump/dump.sh。

cd /home/dump
rq=` date +%Y%m%d%H%M%S`
pid=`ps -A|grep java|awk '{print $1}'`
tnum=`pstree -p $pid | wc -l`
echo ${rq} ${tnum} >> /home/dump/$pid.txt
/usr/java/jdk1.7.0_80/bin/jstack $pid > /home/dump/threaddump_$rq.tdump

在/etc/crontab文件中增加一条记录

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

# For details see man 4 crontabs

# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name command to be executed

01 * * * * root /home/dump/dump.sh

最后一行为增加的,前面五个位置是标识要定时执行的时间。

可执行脚本中,除涉及到系统自带的命令外,其他命令均需用完整路径标识,否则可能会执行不成功。

如果文章对您有用,扫一下支付宝的红包,不胜感激!

欢迎加入QQ群进行技术交流:656897351(各种技术、招聘、兼职、培训欢迎加入)


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK