#监控磁盘
#!/bin/bash
if ! which iostat &> /dev/null
then
yum install -y sysstat
fi
while :
do
iostat -xd 1 5|grep '^sda'| >/tmp/io.log
sum=`awk '{sum=sum+$NF} END {print sum}' /tmp/io.log`
a=`echo "scale=2;$sum/5"|bc`
b=`echo $a|cut -d . -f 1`
if [ $b -gt 90 ]
then
mysql -uroot -pxxx -e "show processlist;" > mysql_$t.log
fi
sleep 1
done
#查看tomcat日志
#!/bin/bash
LANG=en
logfile==`/opt/TOM/$1/logs/catalina.out`
d_mdy=`date "%b %d,%Y"`
if [ $# -ne 2 ] && [ $# -ne 3 ]
then
echo "参数个数不对。"
exit 1
fi
if ! echo $1|grep -qE '^t1$|^t2$|^t3$|^t4$'
then
echo "第一个参数必须是t1,t2,t3或t4"
exit 1
fi
judge_time()
{
date -d "$1" +%s &> /dev/null
if [ $? -ne 0 ]
then
echo "你提供的时间 $1 格式 不正确。"
exit 1
fi
}
tr_24_12()
{
date -d "$1" +%r
}
judge_time_in_log()
{
if ! grep -q "$d_mdy ${tr_24__12 $1}" $logfile
then
echo "你提供的时间$1在日志$logfile中不曾出现,请换个时间。"
exit 1
fi
}
judge_time $2
judge_time_in_log $2
if [ $# -eq 3 ]
then
judge_time $3
t1=`date -d "$2" +%s`
t2=`date -d "$3" +%s`
if [ $t2 -lt $t1 ]
then
echo "你提供的时间$2比$3晚,要把早时间放前面。"
exit
fi
judge_time_in_log $3
fi
begin_n=`grep -n "$d_mdy $(tr_24_12 $2)" $logfile|head -1|awk -F ":" '{print $1}'`
if [ $# -eq 3 ]
then
n=`grep -n "$d_mdy $(tr_24_12 $3)" $logfile|tail -1|awk -F ":" '{print $1}' `
end_n=$[$n+1]
sed -n "$begin_n,$end_n"p $logfile
else
sed -n "$begin_n,$"p $logfile
fi
#打印城市名
#!/bin/bash
read -p "输入5个城市名字,用空格分开。" name
n=`echo $name|awk '{print NF}'`
if [ $n -lt 5 ]
then
echo "请输入至少5个城市名字。"
exit
fi
city=($name)
for i in `seq 0 $[${#city[@]}-1]`
do
echo ${city[$i]}
done
#代码上线
#!/bin/bash
dir=/data/wwwroot/www.aaa.com
B_IP=1.1.1.1
C_IP=2.2.2.2
rs()
{
rsync -azP --exclude="logs" \
--exclude="tmp" --exclude="upload" \
--exclude="caches" $dir/ $1:/dir/
}
rs B_IP
rs C_IP
#统计并发量
#!/bin/bash
LANG=en
t=`date -d "-1 second" +%d/%b/%Y:%`
log=/data/logs/www.aaa.com_access.log
tail -1000|grep -c "$t" $log