linux写定时脚本 重启部署tomcat

1、安装

yum install  vixie-cron

yum install  crontabs

 

2、启动    service crond start

 

3、设置开机自启: systemctl enable crond.service

 

4、添加定时任务

vim /etc/crontab

在末尾添加   */1 * * * * root /opt/demo.sh >> /opt/demo.txt

过一分钟看demo.txt里有记录了

 

5、demo.sh示例内容

#!/bin/bash

tomcat_home=/usr/local/tomcat
SHUT_DOWN=$tomcat_home/bin/shutdown.sh
START_UP=$tomcat_home/bin/startup.sh


echo 'hello'
###########################      tomcat    #############################

PID=`ps -ef |grep $tomcat_home/conf  |grep -v grep | awk '{print $2}'`

if [ ! "$PID" ];then
  echo 'proccess dont exist'
else
  echo 'kill process PID:$PID'
  kill -9 $PID
fi

current_time=/opt/web_bak/$(date "+%Y%m%d") 
echo $current_time
if [ ! -d "$current_time" ];then
  mkdir $current_time
else
  echo "file exist"
fi

#back old war
if [ -f "$tomcat_home/webapps/demo.war" ];then
  cp $tomcat_home/webapps/demo.war $current_time/
fi

#use new war
if [ -f "/opt/demo.war" ];then
  cp /opt/demo.war $tomcat_home/webapps/
fi

$START_UP

echo 'end'



 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值