shell 记录

数组,多线程  

urlcmd='/root/cmd/'
for i in {0..47}
do
        arr=(`${urlcmd}cmd $i  | grep 'Number'|awk -F '[' '{print $2}'|awk -F ']' '{print $1}'`)
        if [ -z ${#arr[*]} ];then
                :
        else
                for j in "${!arr[@]}"
                do
                {
                        on_chain=`${urlcmd} ${arr[$j]} --on-`
                        ticket=`echo $on_chain | grep -E 'Ticket:'|awk '{print $10}'`
                        commR=`echo  $on_chain | grep -E 'CIDcommR:'|awk '{print $8}'`
                        echo "--id=${arr[$j]} --ticket=${ticket} --commR=${commR}" >> t.file
                } &
                done
        fi
done

 文件刷新时间计算,日志文件截取

#!/bin/bash
str=`tail -n 1 recove.log | grep 'removin'`
str1=`tail -n 1 recove.log | grep 'Fetchin'`
if [ -z "$str" -o -z "$str1" ];then
        file='recove.log'
        #获取文件修改时间
        last_time=$(stat -c %Y $file)
        #获取当前时间
        ndate=`date +%s`
        #文件修改时间
        timediff=$[$ndate -$last_time]
        if [ $timediff -gt 300 ];then
                #获取id
                [ ! -z "$str" ] && id=`echo $str |grep -oE "sector [0-9]+" |awk '{print $2}'`
                [ ! -z "$str1" ] && id=`echo $str1 |grep -oE "sector [0-9]+" |awk '{print $2}'`
                if [ -f s-t0470608-$id -a -f $id ];then
                        filesize=`ls -l s-t0470608-$id | awk '{print $5}'`
                        if [ $filesize -eq 68719476736 ];then
                                kill -9 $(ps -e|grep ' lotus-recover$'|awk '{printf $1}')
                        fi
                else
                        echo "缺少/文件"
                fi

        fi
fi

你可能感兴趣的:(bash,linux,开发语言)