#!/bin/bash

#

fdir="/tmp/first"sdir="/tmp/second"tdir="/tmp/third"fodir="/tmp/forth"ColLogs() {

echo"收集原始系统日志:"[-d $fdir ] && rm -rf $fdir && mkdir $fdir ||mkdir $fdir

#weblist=`salt "主机名" test.ping | grep -v "True" | awk -F ‘:‘ ‘{print $1}‘`

#list="`salt"主机名"test.ping | grep -v"True"| awk -F ‘:‘ ‘{print $1}‘ | xargs echo`"list="`salt"主机名"test.ping | grep -v"True"| xargs echo | sed"s/://g"`"

for i in $list; dosalt"$i" state.sls zhouz.copydir &> $fdir/$i

echo"$i is ok"done

}

TreatLogsA() {

echo"整理初始化日志(为对比天、小时、分钟、秒钟等字符串是否一致做准备):"[-d $tdir ] && rm -rf $tdir && mkdir $tdir ||mkdir $tdir

cd $fdirfor i in $(ls BX*); dogrep-A 1 ReplacementStrings $i | xargs echo >$tdir/$i

cd $tdir

sed-i ‘s/--/&\n/g‘$i

sed-i ‘s/--\|{\|}\|[[:space:]]//g‘$i

#sed-i ‘s/,/ /g‘$i

sed-i ‘s/,/\./g‘$i

sed-i ‘s/Z//g‘$i

#sed-i ‘s/\./:/g‘$i

sed-i ‘s/ReplacementStrings://g‘$i

#sed-i ‘s/T/:/g‘$i

#sed-i ‘s/2019-07-[0-9][0-9]T//g‘$i

#sed-i ‘s/\.[0-9]\{4,10\}Z//g‘$i

echo"$i is ok"cd $fdir

done

}

TreatLogsB() {

echo"对收集的初始系统日志进行整理(为对比 毫秒差值 做准备):"[-d $sdir ] && rm -rf $sdir && mkdir $sdir ||mkdir $sdir

cd $fdirfor i in $(ls BX*); dogrep-A 1 "ReplacementStrings" $i | xargs echo >$sdir/$i

cd $sdir

sed-i ‘s/--/&\n/g‘$i

sed-i ‘s/--\|{\|}\|[[:space:]]\|Z//g‘$i

sed-i ‘s/,/:/g‘$i

sed-i ‘s/\,\ 1//g‘$i

# sed-i ‘s/\./:/g‘$i 此处将 . 去掉

sed-i ‘s/\.//g‘$i

sed-i ‘s/ReplacementStrings://g‘$i

sed-i ‘s/T/:/g‘$i

# sed-i ‘s/2019-07-[0-9][0-9]T//g‘$i

echo"$i is ok"cd $fdir

done

}

TreatLogsC() {

echo"对收集的初始系统日志进行整理(为对比 秒差值 做准备):"[-d $fodir ] && rm -rf $fodir && mkdir $fodir ||mkdir $fodir

cd $fdirfor i in $(ls BX*); dogrep-A 1 ReplacementStrings $i | xargs echo >$fodir/$i

cd $fodir

sed-i ‘s/--/&\n/g‘$i

sed-i ‘s/--\|{\|}\|[[:space:]]\|Z//g‘$i

sed-i ‘s/,/:/g‘$i

sed-i ‘s/\./:/g‘$i

#sed-i ‘s/\.//g‘$i

sed-i ‘s/ReplacementStrings://g‘$i

sed-i ‘s/T/:/g‘$i

#sed-i ‘s/2019-07-[0-9][0-9]T//g‘$i

echo"$i is ok"cd $fdir

done

}

LogsDay() {

echo"对比两列数据中秒钟是否一致:"cd $fodir

mkdir $fodir/dtime &>/dev/null

for i in $(ls BX*); do#cat $i| awk -F ":" ‘{print $1,":"$2,":"$3,($4-$9)}‘ >$fodir/dtime/$i

cat $i| awk -F ":" ‘{print ($4-$9)}‘ >$fodir/dtime/$i

cd $fodir/dtime

#count=`grep -E -v "0|1" $i | wc -l`

count=`grep -E -v "0" $i | wc -l`if [ $count -ge 1]; then

echo"$i have problem"grep-v ‘0‘$ielseecho"$i is ok"fi

cd $fodir

done

}

DisTimePeriodA() {

echo"对比天、小时、分钟、秒钟等字符串是否一致(批量)"cd $tdir

mkdir $tdir/dtime &>/dev/nullread_file=‘BX*‘

for file in ${read_file}; doecho"$file"

for ((i=1;i<=$(cat $file| wc -l);i++)); do#first="$(sed -n ${i}p $file| awk ‘{print $1}‘)"first="$(sed -n ${i}p $file| awk -F"."‘{print $1}‘)"#second="$(sed -n ${i}p $file | awk ‘{print $2}‘)"second="$(sed -n ${i}p $file | awk -F"."‘{print $3}‘)"#echo"${first}"#echo"${second}"

if [ "${first}" == "${second}"]; then

echo"${first} = ${second}" &>/dev/null

elseA="$(grep $first $file)"#B="$(grep $second $file)"#echo"${first} != ${second}"echo"${A}"fi

done

echo" "done

}

DisTimePeriodB() {

echo"对比天、小时、分钟、秒钟等字符串是否一致(只查询有问题的主机)"cd $tdir

mkdir $tdir/dtime &>/dev/null#read_file=‘BX*‘#for file in ${read_file}; doread-p "请输入有问题的主机名:"file

echo"$file" >>$tdir/dtime/$filefor ((i=1;i<=$(cat $file| wc -l);i++)); do#first="$(sed -n ${i}p $file| awk ‘{print $1}‘)"first="$(sed -n ${i}p $file| awk -F"."‘{print $1}‘)"#second="$(sed -n ${i}p $file | awk ‘{print $2}‘)"second="$(sed -n ${i}p $file | awk -F"."‘{print $3}‘)"

if [ "${first}" == "${second}"]; then

echo"${first} = ${second}" &>/dev/null

else#echo"${first} != ${second}" >>$tdir/dtime/$file

A="$(grep $first $file)"echo"${A}"fi

# echo" " >>$tdir/dtime/$file

done

#done

}

LogsMillisecond() {

echo"对比两列数据中 毫秒 是否一致:"cd $sdir

mkdir $sdir/mtime &>/dev/null

for i in $(ls BX*); docat $i| awk -F ":" ‘{print $1,":"$2,":"$3,($4-$8)}‘ | sort -t $‘ ‘ -k4 -n >$sdir/mtime/$i

cd $sdir/mtime

echo"=================================================="echo"$i 两列毫秒为正数的数值最高的10个"cat $i|tail

#echo"=================================================="#echo"$i 两列毫秒为正数的数值最小的10个"#cat $i|grep -v ‘\-[0-9][0-9][0-9][0-9][0-9]‘ |head -15echo"=================================================="echo"$i 两列毫秒为负数的数值最大的10个"cat $i|grep ‘\-[0-9][0-9][0-9][0-9]‘ |head

#echo"=================================================="#echo"$i 两列毫秒为负数的数值最小的10个"#cat $i|grep ‘\-[0-9][0-9][0-9][0-9]‘ |tail

cd $sdir

done

}

#ColLogs

a="ColLogs"b="TreatLogsA"c="TreatLogsB"d="TreatLogsC"e="LogsDay"f="DisTimePeriodA"g="DisTimePeriodB"h="LogsMillisecond"echo"请选择你想要执行的功能:

a: ColLog

收集windows server初始日志;

b: TreatLogsA

整理初始化日志(为对比天、小时、分钟、秒钟等字符串是否一致做准备);

c: TreatLogsB

整理初始化日志(为对比 毫秒 差值做准备);

d: TreatLogsC

整理初始化日志(为对比 秒 差值做准备);

e: LogsDay

对比两列数据中<< 秒 >>是否一致;

f: DisTimePeriodA 对比天、小时、分钟、秒钟等字符串是否一致(批量显示);

g: DisTimePeriodB 对比天、小时、分钟、秒钟等字符串是否一致(只查询有问题的主机);

h: LogsMillisecond 对比两列数据中<< 毫秒 >>是否一致."read-n3 -p "请输入:"optcase $opt ina)

$a ;;

b)

$b ;;

c)

$c ;;

d)

$d ;;

e)

$e ;;

f)

$f ;;

g)

$g ;;

h)

$h ;;*)

echo"No opt"exit1esac


本文参考链接:https://blog.csdn.net/weixin_42525428/article/details/119589587
评论关闭
IT序号网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!