日期:2014-05-16  浏览次数:20612 次

linux下定时启动Java程序

由于项目需要客户要求每天要13点要重启一次Java程序。由于项目部署在RedHat下运行,故首要考虑使用Cron定时任务

具体操作及源码以下:

1、定义重启脚本


#!/bin/bash
cd /root/tools/mail/


#kill ReceiveMail/SendMail
ps -ef | grep ReceiveMail | grep -v grep | cut -c 9-15 | xargs kill -s 9
ps -ef | grep SendMail | grep -v grep | cut -c 9-15 | xargs kill -s 9




#start ReceiveMail/SendMail
nohup sh ./receiveMail.sh &
nohup sh ./sendMail.sh &


2、增加Cron定时任务

打开终端输入crontab –e后增加以下内容

1 13 * * * sh /root/tools/mail/startAll.sh(注意路径)


至此,大功告成。