1.uptime日志脚本(每天记录)

#!/bin/sh

dir=/tmp/uptime_log

process=`ps -ef|grep $|grep -v "grep" |grep -v "vim"|grep -v "ps"|wc -l`
if [ $process -gt ];then
echo $process
exit;
fi if [ ! -d $dir ];then
mkdir -p $dir;
fi while true
do
current_time=`date -d today +"%Y_%m_%d"`
uptime >> ${dir}/${current_time}_system_check.txt
sleep ;
find $dir -mtime +${time} -type f|xargs rm -rf
chown -R xxadmin.xxadmin ${dir}/*
done

2.tomcat日志切割

#!/bin/bash
file1='/usr/local/tomcat7/logs'
file2='/usr/local/tomcat7-2/logs'
file3='/usr/local/tomcat7-3/logs'
file4='/usr/local/tomcat7-4/logs'
logtime="`date +20%y_%m_%d`"
time=
for i in `seq `
do
{
rm -rf tmp_${i}.txt
eval echo \$file${i} > tmp_${i}.txt
file=`cat tmp_${i}.txt`
cp $file/catalina-daemon.out $file/catalina-daemon_${logtime}.out
if [ $? -eq ];then
echo "" > $file/catalina-daemon.out
fi chown zxadmin.zxadmin $file/catalina-daemon_${logtime}.out find $file -mtime +${time} -type f|grep catalina-daemon_*.out|xargs rm -rf
rm -rf tmp_${i}.txt }
done

3.远程拷贝日志脚本

#!/bin/sh

time=`date -d "1 day ago" +"%Y_%m_%d"`

file=catalina-daemon_${time}.out
dir1=/usr/local/tomcat7/logs
dir2=/usr/local/tomcat7-/logs
dir3=/usr/local/tomcat7-/logs
dir4=/usr/local/tomcat7-/logs
remote_ser1=111.111.111.1
remote_ser2=111.111.111.2
remote_ser3=111.111.111.3
local_dir=/tmp/log_list
times=
pro1=xxx_web
pro2=xxx_api
pro3=xxx_manage
pro4=xxx_forward uptime_log_dir=/tmp/uptime_log
uptime_file=${time}_system_check.txt
local_uptime_file1=xxx_web
local_uptime_file2=xxxx_db
local_uptime_file3=xxx_nginx if [ ! -d $local_dir/$time ];then
mkdir -p $local_dir/$time;
fi
rm -rf $local_dir/$time/* #tomcat_log
for i in `seq 1 4`
do
{ rm -rf /tmp/.tmp_a_${i}.txt
eval echo \$dir${i} > /tmp/.tmp_a_${i}.txt
dir=`cat /tmp/.tmp_a_${i}.txt` rm -rf /tmp/.tmp_b_${i}.txt
eval echo \$pro${i} > /tmp/.tmp_b_${i}.txt
pro=`cat /tmp/.tmp_b_${i}.txt` ssh $remote_ser1 "cd ${dir};tar -zcf catalina-daemon_${time}.out.gz catalina-daemon_${time}.out > /dev/null 2>&1"
if [ $? -ne 0 ];then
echo `date`'--->tar tomcat_log faile' >> $local_dir/$time/error.log;
exit;
fi scp $remote_ser1:$dir/$file.gz $local_dir/$time > /dev/null 2>&1
if [ $? -ne 0 ];then
echo `date`'--->scp tomcat_log.gz faile' >> $local_dir/$time/error.log;
exit;
fi ssh $remote_ser1 'rm -rf $dir/${file}.gz > /dev/null 2 >& 1'
if [ $? -ne 0 ];then
echo `date`'--->rm the tomcat_log.gz file faile' >> $local_dir/$time/error.log; fi cd $local_dir/$time;tar -zxf $local_dir/$time/${file}.gz -O > ${pro}_${file}; find $local_dir -mtime +${times} -type d |grep catalina*.out|xargs rm -rf }
done #uptime_log
for i in `seq 1 3`
do rm -rf /tmp/.tmp_c_${i}.txt
eval echo \$remote_ser${i} > /tmp/.tmp_c_${i}.txt
remote_ser=`cat /tmp/.tmp_c_${i}.txt` rm -rf /tmp/.tmp_d_${i}.txt
eval echo \$local_uptime_file${i} > /tmp/.tmp_d_${i}.txt
local_uptime_file=`cat /tmp/.tmp_d_${i}.txt` ssh $remote_ser "cd ${uptime_log_dir};tar -zcf ${uptime_file}.gz ${uptime_file} "
if [ $? -ne 0 ];then
echo `date`'--->tar uptime_file faile' >> $local_dir/$time/error.log;
exit;
fi scp $remote_ser:${uptime_log_dir}/${uptime_file}.gz $local_dir/$time > /dev/null 2>&1
if [ $? -ne 0 ];then
echo `date`'--->scp uptime_file faile' >> $local_dir/$time/error.log;
exit;
fi ssh $remote_ser 'rm -rf ${uptime_log_dir}/${uptime_file}.gz > /dev/null 2 >& 1'
if [ $? -ne 0 ];then
echo `date`'--->rm uptime_file.gz faile' >> $local_dir/$time/error.log;
exit;
fi cd $local_dir/$time;tar -zxf $local_dir/$time/${uptime_file}.gz -O > ${local_uptime_file}_${uptime_file};
done
rm -rf $local_dir/$time/*.gz
rm -rf /tmp/.tmp_*.txt /home/zxadmin/filter_xdaili_log.sh
if [ $? -ne 0 ];then
echo `date`'--->filter xdaili log file faile!' >> $local_dir/$time/error.log;
fi

4.日志过滤

#!/bin/bash

time=`date -d "1 day ago" +"%Y_%m_%d"`
local_dir=/tmp/log_list
files=`ls ${local_dir}/${time}|grep "xxdaili"`
dir1=filter_files cd ${local_dir}/$time
if [ ! -d $dir1 ];then
mkdir -p $dir1;
fi
rm -rf $dir1/* for i in $files
do
if [ ! -f $i ];then
echo $i' not found' >> $dir1/error.log;
else
name=`echo $i|awk -F"." '{print$2}'`
if [ $name = "txt" ];then
cat $i |grep -v "min"|awk '{print$1"\t"$12}' > $dir1/$i
elif [ $name = "out" ];then
cat $i |grep 'Exception\|at ' > $dir1/$i
fi fi done

centos记录uptime,tomcat日志切割,远程拷贝日志脚本的更多相关文章

  1. nginx 日志切割(也适用于docker)

    =============================================== 2019/4/6_第2次修改                       ccb_warlock 201 ...

  2. 日志切割之Logrotate

    1.关于日志切割 日志文件包含了关于系统中发生的事件的有用信息,在排障过程中或者系统性能分析时经常被用到.对于忙碌的服务器,日志文件大小会增长极快,服务器会很快消耗磁盘空间,这成了个问题.除此之外,处 ...

  3. Logrotate日志切割

    日志切割Logrotate 关于日志切割 logrotate程序是一个日志文件管理工具.用于分割日志文件,删除旧的日志文件,并创建新的日志文件,起到"转储"作用. 可以节省磁盘空间 ...

  4. 日志切割logrotate和定时任务crontab详解

    1.关于日志切割 日志文件包含了关于系统中发生的事件的有用信息,在排障过程中或者系统性能分析时经常被用到.对于忙碌的服务器,日志文件大小会增长极快,服务器会很快消耗磁盘空间,这成了个问题.除此之外,处 ...

  5. Nginx 热部署和日志切割,你学会了吗?

    上篇文章,我们已经安装好 Nginx,并且配置好 Nginx 文件后,这个时候我就需要操作 Nginx 的命令行了,这篇文章主要讲解 Nginx 命令行相关知识,并通过日常遇到的热部署.切割日志文件场 ...

  6. linux shell:nginx日志切割脚本

    需求原因:nginx不具备日志切割功能,日志量较大,方便分析. 实现目的:完成nginx日志切割,并根据时间命名   简要命令: mv /usr/local/tengine/logs/access.l ...

  7. nginx日志切割总结

    Nginx日志切割   方法1(脚本+定时执行): #step1:加脚本 cut_nginx_log.sh,主进程把USR1信号发给worker,worker接到这个信号后,会重新打开日志文件 #!/ ...

  8. Nginx定时日志切割

    Nginx定时日志切割 现有的日志都会存在access.log文件中,但是随着时间的推移,这个文件的内容会越来越多,体积会越来越大,不便于运维 人员查看,所以我们可以通过把这个大的日志文件切割为多份不 ...

  9. tomcat集群日志切割和远程备份脚本分享

    笔者一共有3台tomcat服务器,一共4个tomcat服务,未来还会增加4个作为负载,笔者想通过在存储服务器对tomcat服务的日志进行远程切割和备份到存储上. 文中采用清空日志的方式,优点是不用重启 ...

随机推荐

  1. java okhttp包的类特点

    1.开始使用这个包时候不习惯,觉得api用起来很别扭,不管是Request okhttpClient formBody只要是设置啥,就必须使用类里面的Builder类,然后一个方法接受一个参数,不停地 ...

  2. linux alias使用

    安装一些软件 python redis mysql jdk,都需要添加环境变量,一个路径添加到了环境变量,就可以直接在linux控制台输入  xx命令. 否则不添加环境变量,使用xx就会提示找不到命令 ...

  3. Unity3D的按钮添加事件有三种方式

    为Unity3D的按钮添加事件有三种方式,假设我们场景中有一个Canvas对象,Canvas对象中有一个Button对象. 方式一: 创建脚本ClickObject.cs,然后将脚本添加到Canvas ...

  4. Aspose------导出Excel

    代码: /// <summary> /// 导出Excel /// </summary> /// <typeparam name="T">泛型类 ...

  5. RHEL5 yum更新源

    1.检查yum是否安装 rpm -qa |grep yum 2.利用CentOS的yum更新源来实现RHEL5的YUM功能 vi /etc/yum.repos.d/CentOS-Base.repo [ ...

  6. 第四章 TCP粘包/拆包问题的解决之道---4.1---

    4.1 TCP粘包/拆包 TCP是一个“流”协议,所谓流,就是没有界限的一串数据.TCP底层并不了解上层业务数据的具体含义,它会根据TCP缓冲区的实际情况进行包的划分,所以在业务上认为,一个完整的包可 ...

  7. javascript全屏操作

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. 给自己的android扫盲文 - 1

    1. 你得知道,android开发打一开始就是java的事,没其它语言什么事情,就是说google提供的android sdk中的api都是java的api2. 至于强大的跨平台语言,你懂的,非c/c ...

  9. Sharepoint文档的CAML分页及相关筛选记录

    写这篇文章的初衷是因为其他的业务系统要调用sharepoint的文档库信息,使其他的系统也可以获取sharepoint文档库的信息列表.在这个过程中尝试过用linq to sharepoint来获取文 ...

  10. 查看一个dll是否是强命名[C#]

    使用命令行工具SDK Command Prompt,键入:SN -T C:\*****.dll 就会显示出该dll具体的PublicKeyToken 数值. 如果该程序集没有强命名,则不会有Publi ...