linux 查看tomcat状态和日志

一般服务器部署在linux系统中,

那么在linux 系统中如何查看tomcat日志呢?

 

场景1:浏览器报错了,如何定位错误

查看tomcat 日志的尾部

tail -n 50 ../../logs/catalina.out

 tail表示只显示catalina.out 最后n 行

 

场景2:如何实时查看tomcat日志内容呢?

tail -f ../../logs/catalina.out

 

 

场景3:通过关键字查询日志

grep -nH "Excetion message" test.text

说明:grep的参数说明

 -n, --line-number 行号

-H, --with-filename 打印每个匹配的文件名 

-r, --recursive           like --directories=recurse 递归

 

判断tomcat是否在运行

#!/bin/sh
$grep_result
grep_result=`ps -ef |grep tomcat|grep "/home/whuang/software/apache/apache-tomcat-7.0.53"|grep -v "grep"`
echo $grep_result
    if [ x"$grep_result" = x"" ];then
        echo "tomcat not run"
    else
        echo "tomcat is running..."  
    fi

 

定时启动tomcat

编辑定时器:

crontab -e

 

*/1 * * * * /home/whuang/software/auto_start_tomcat.sh

每隔一分钟就执行指定脚本

 

 脚本内容如下:

#!/bin/sh
$grep_result
grep_result=`ps -ef |grep tomcat|grep "/home/whuang/software/apache/apache-tomcat-7.0.53"|grep -v "grep"`
if [ x"$grep_result" = x"" ];then

        catalina_home2=/home/whuang/software/apache/apache-tomcat-7.0.53
        CATALINA_HOME=$catalina_home2
        cd $catalina_home2/bin
        ./startup.sh
    else
        echo "tomcat is running..."  
    fi

 

每天的上午7点30分执行脚本:

30 7 * * *  /home/whuan/software/auto_start_tomcat.sh

 

每天的下午6点执行脚本:

30 18 * * *  /home/whuan/software/auto_innerSign.sh 

 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值