Shell脚本实现log版本号的提取

#!/bin/sh

MAXSIZE=300
TMPFILE=./device.tmp
RESULTFILE=$1/device_info.log
FILE=./tmpdevice_info.log

CUR_TIME=`date "+%Y-%m-%d %H:%M:%S%:z "`
echo -n $CUR_TIME > $FILE
echo -n " " >> $FILE
dcli plmgrd xshow info | grep uptime  > $TMPFILE

tmpcache=`cat $TMPFILE | awk '{print $2 }'`
if [[ $tmpcache =~ "cpu-usage" ]]
then
    echo $tmpcache
    echo $tmpcache  > $TMPFILE
fi
tmpcache=`cat $TMPFILE | awk '{print $3 }'`
if [[ $tmpcache =~ "cpu-usage" ]]
then
    echo $tmpcache
    echo $tmpcache  > $TMPFILE
fi
tmpcache=`cat $TMPFILE | awk '{print $4 }'`
if [[ $tmpcache =~ "cpu-usage" ]]
then
    echo $tmpcache
    echo $tmpcache  > $TMPFILE
fi

sed -i "s// /g" $TMPFILE
sed -i "s/<\/cpu-usage>/ /g" $TMPFILE

CPUUSAGE=`cat $TMPFILE | awk '{print $2 }'`
echo $CPUUSAGE
echo -n cpu-usage:$CPUUSAGE >> $FILE
echo -n " " >> $FILE
tmpcache=`cat $TMPFILE | awk '{print $3}'`
echo $tmpcache > $TMPFILE

sed -i "s// /g" $TMPFILE
sed -i "s/<\/available-memory>/ /g" $TMPFILE

AVAILABLEMEM=`cat $TMPFILE | awk '{print $2 }'`
echo $AVAILABLEMEM
echo -n available-memory:$AVAILABLEMEM  >> $FILE
echo -n " " >> $FILE
tmpcache=`cat $TMPFILE | awk '{print $3}'`
echo $tmpcache > $TMPFILE

sed -i "s// /g" $TMPFILE
sed -i "s/<\/system-temperature>/ /g" $TMPFILE

SYSTEMTEMP=`cat $TMPFILE | awk '{print $1 }'`
echo $SYSTEMTEMP
echo -n system-temperature:$SYSTEMTEMP  >> $FILE
echo -n " " >> $FILE
tmpcache=`cat $TMPFILE | awk '{print $2}'`
echo $tmpcache > $TMPFILE

sed -i "s// /g" $TMPFILE
sed -i "s/<\/used>/ /g" $TMPFILE

SDA1USAGE=`cat $TMPFILE | awk '{print $6 }'`
SDA2USAGE=`cat $TMPFILE | awk '{print $8 }'`

echo -n sda1:$SDA1USAGE   >> $FILE
echo -n " " >> $FILE
echo -n sda2:$SDA2USAGE   >> $FILE
echo -n " " >> $FILE

dcli notfmgrd xshow health summary | grep show- > $TMPFILE
sed -i "s// /g" $TMPFILE
sed -i "s/<\/health-status>/ /g" $TMPFILE
HEALTHSTATUS=`cat $TMPFILE | awk '{print $2}'`
echo $HEALTHSTATUS
echo -n health-status:$HEALTHSTATUS >> $FILE
echo -n " " >> $FILE

CARDSTATUS=`dcli lmd debug dump global | grep "PSM state" | awk '{print $4}' | cut -f1 -d '('`
echo $CARDSTATUS
echo -n cardstatus:$CARDSTATUS >> $FILE
echo -n " " >> $FILE

CARDTYPE=`dcli equipmentmgrd show card | grep provision | awk '{print $2}'`
echo $CARDTYPE
echo -n cardtype:$CARDTYPE >> $FILE
echo -n " " >> $FILE

DEVICETYPE=`dcli lmd debug dump global | grep "System Type" | awk '{print $4}'`
echo $DEVICETYPE
echo devicetype:$DEVICETYPE >> $FILE

cat $FILE >> $RESULTFILE

FILE_SIZE=`du $RESULTFILE | awk '{print $1}'`

if [ $FILE_SIZE -ge $MAXSIZE ]
then
        rm $RESULTFILE -rf
fi

你可能感兴趣的:(calix学习)