1.查看僵死进程
ps -Ao stat,pid,%cpu,%mem,cmd | egrep '^[Zz]'
2.顺序批量解压文件
for((i=1;i<23;i++));do tar -zxvf "990191222$(printf '%02d' $i).npd.tar.gz" ;sleep 5 ;done;
3.循环显示时间
while(true); do date; sleep 1; done;
4.使用多进程pgiz压缩上月文件
REQ_NAME=$(date -d "-1 month" +"user%Y%m*");
GZ_NAME=$(date -d "-1 month" +"use%Y_%m.tar.gz");
FILE_NUM=$(find -type f -name "$REQ_NAME" |wc -l)
if((FILE_NUM>0));
then
time tar -zcvf - $REQ_NAME | pigz -p 20 > $GZ_NAME;
rm $REQ_NAME
else
echo "没有文件";
fi;
exit;
5.多进程查询输出
cd /oracledb/Ticket_JF/bak/LOCAL/2019/07
tmp_fifofile=”$$.fifo”
mkfifo $tmp_fifofile # 新建一个fifo类型的文件
exec 6<>$tmp_fifofile # 将fd6指向fifo类型
rm $tmp_fifofile
thread=10; # 此处定义线程数
trw=();
trw=($(cat hm.log));
FL=${#trw[*]};
echo $FL;
for ((i=0;i<$thread;i++));
do
echo
done >&6 # 事实上就是在fd6中放置了$thread个回车符
for (( j=0; j<$FL; j++ ));
do
read -u6
{
num=${trw[$j]};
echo -e $j;
echo -e $num;
grep -r $num 01/* >> hd.log;
grep -r $num 02/* >> hd.log;
grep -r $num 03/* >> hd.log;
grep -r $num 04/* >> hd.log;
grep -r $num 05/* >> hd.log;
grep -r $num 06/* >> hd.log;
grep -r $num 07/* >> hd.log;
echo >&6
}&
done
wait # 等待所有的后台子进程结束
exec 6>&- # 关闭df6
exit 0
6. 查找包含07-22到07-27 之间的记录
sed -n '/^07-22/,/^07-27/p' RecvData.log |more
7.分类统计日志上一分钟处理量
egrep "$(date -d '-1 minute' +'%m-%d %H:%M')" MtWork.log|awk -F'[] []' '{if ($0~"Recv Msg") print $1,substr($2,1,5),$3,$4;else if ($0~"IDMS Resp"&&$0!~"Errorcode\\[0") print $1,substr($2,1,5),$3,$4,$9":"$10;else if ($0~" Send SMSC") print $1,substr($2,1,5),$3,$4;else if ($0~"SMSC Resp") print $1,substr($2,1,5),$3,$4,$13":"$14}'|sort |uniq -c
8.查看CPU,内存,硬盘使用百分比
#SUSE11版
C=$(awk 'BEGIN{printf "%.1f%\n",(100-'$(top -b -n 1 -d 1 |grep Cpu| awk '{print $5}'|sed 's/\%id,//')')}')&&
M=$(awk 'BEGIN{printf "%.2f%\n",('$(free|grep buffers/cache|awk '{ print $3}')'/'$(free|grep Mem|awk '{ print $2 }')')*100}')&&
D=$(df -h |grep 'home' |awk '{ print $5}')&&
echo -e 'CPU\t内存\t硬盘\n'$C'\t'$M'\t'$D;
##优化
C=$(top -n1 |awk '/Cpu/{print $5}'|awk -F '[%]' '{printf "%.2f%%",100-$1}') &&
M=$(free |awk '/cache:/{printf "%.2f%%",$3/($3+$4)*100}')&&
D=$(df |awk '/home/{print $5}')&&
echo -e 'CPU\t内存\t硬盘'&&
echo -e $C'\t'$M'\t'$D'\n'&&
echo -e $C'#'$M'#'$D
#SUSE12版
C=$(awk 'BEGIN{printf "%.1f%",(100-'$(top -b -n 1 -d 1 |grep Cpu| awk '{print $8}')')}')&&
M=$(awk 'BEGIN{printf "%.2f%",('$(free|grep buffers/cache|awk '{ print $3}')'/'$(free|grep Mem|awk '{ print $2 }')')*100}')&&
D=$(df -h |grep 'home' |awk '{ print $5}')&&
echo -e 'CPU\t内存\t硬盘\n'$C'\t'$M'\t'$D;
##优化
C=$(top -n1 |awk '/Cpu/{printf "%.2f%%\n",100-$8}')&&
M=$(free |awk '/cache:/{printf "%.2f%%\n",$3/($3+$4)*100}')&&
D=$(df |awk '/home/{print $5}')&&
echo -e 'CPU\t内存\t硬盘'&&
echo -e $C'\t'$M'\t'$D'\n'&&
echo -e $C'#'$M'#'$D
9、查看进程的IO
pidstat -l -d 1
10、移动文件到对应天目录
创建天目录
for i in {0..30} ; do Day1=$(date -d "2021-01-01 +$i day" +%d); echo $Day1; md $Day1; done
11、移动文件
find -maxdepth 1 -name "user\[?\]202101*" -type f |awk '{print $1,substr($1,16,2)"/"}'|xargs -tn 2 mv
12、查询僵死线程及父进程
ps -eo stat,pid,ppid,nlwp,rsz,cmd|egrep $( ps -eo pid,ppid,stat|awk -v ORS="|" '$3~/[Zz]/{print $1"|"$2"|STAT"}'|sed 's/|$//')|egrep -v 'grep|awk'