Linux shell script periodically cleans Tomcat log files (first draft) __linux

Source: Internet
Author: User

Shell script to clean up logs

------------------------------------------------------------------------------------------------

#!/bin/bash

tomcatnum=2

#清理的路径 tomcat[0]= "/usr/local/tomcat/logs"
tomcat[1]= "/data/logs/tomcat0"


For ((i=0;i< $tomcatnum; i++));d o
echo "Deleting ${tomcat[i]}"
RM-RF ${tomcat[i]}/*
#echo $i
Done


Tom_catalog= "Tomcat"

#根据tomcat名称进行查询

process_num=$ (ps-ef|grep "$tom _catalog" |grep-v "grep" |wc-l)

#得到pid

#pid =$ (ps-ef|grep "$tom _catalog" |grep-v "grep" | awk ' {print $} ') echo $PROCESS _num
If [$PROCESS _num-ge 1];
Then
Echo ' Tomcat is stopping ... '

/usr/local/tomcat/bin/shutdown.sh

#kill-9 $pid Sleep 200
echo "Tomcat is running ..."
/usr/local/tomcat/bin/startup.sh
Else
Echo ' Tomcat is running '
/usr/local/tomcat/bin/startup.sh
Fi

_____________________________________________________

Add the shell script to the timer boot

/var/spool/cron/

VI Root

0 * * 6/usr/local/script/***.sh

Restart Corn

/sbin/service Cron Restart

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.