crontab 定时任务设置
安装包
yum install vixie-cron
yum install crontabs
开机启动
chkconfig --level 35 crond on
启动服务
service crond start
编辑定时任务文件
vi /etc/crontab
*/1 * * * * /home/sh/delete_log.sh 每分钟
sh脚本给执行权限
rm -rf `date -d yesterday +"/data/logs/node_ai/log_%Y-%m-%d.txt"`
rm -rf `date -d yesterday +"/data/logs/base_node/log_%Y-%m-%d.txt"`
#加载任务,使之生效
crontab /etc/crontab
#查看任务
crontab -l
MySQL链接超时释放脚本
#!/bin/sh MYSQLDIR=/usr/local/mysql/bin MYSQLTOOL=$MYSQLDIR/mysql MYSQLUSER=weixin MYSQLPASS=Weixin*2018 # usage() # { # echo "Usage: $0 ip port db_user" # echo "Example: $0 127.0.0.1 3306 db_user" # exit # } # if [ $# -ne 3 ];then # usage # fi hostip='mysql.rds.aliyuncs.com' port='3306' dbname='dati' sleepid="SELECT ID FROM information_schema.PROCESSLIST t WHERE t.COMMAND='Sleep' and DB='$dbname' and time >100;" echo $sleepid $MYSQLTOOL -h$hostip -u$MYSQLUSER -p$MYSQLPASS -P$port -e "$sleepid" >sleepIDs sed -i '1d' sleepIDs while read sID do echo $sID $MYSQLTOOL -h$hostip -u$MYSQLUSER -p$MYSQLPASS -P$port -e "kill $sID" done<sleepIDs
Keep going