#!bin/bash
#connect
##################################################################
#功能描述:每5分钟检查一次单板状态,如果单板假死了就将单板复位重启
#执行周期:5分钟
#CRONTAB:5 * * * *
#作 者:洪杰
#创建时间:2016/08/03
#修改记录:
##################################################################
#保证每次这个文件为空
rm -rf hubei_CSMII_JK.log
#将查询结果输入到hubei_CSMII_JK.log文件中
{
sleep 2
printf "hongjie\r\n"
sleep 2
printf "hongjie\r\n"
sleep 2
printf ":display-board-status:slot=3;\r\n"
sleep 10
} | telnet 192.168.110.235 23 >> hubei_CSMII_JK.log
#取出7个监控指标的值
v_SERVICE=`cat hubei_CSMII_JK.log|grep SERVICE|awk '{print $NF}'`
v_ONLINE=`cat hubei_CSMII_JK.log|grep ONLINE|awk '{print $NF}'`
V_IOPORT=`cat hubei_CSMII_JK.log|grep IOPORT|awk '{print $NF}'`
V_ICP=`cat hubei_CSMII_JK.log|grep ICP|awk '{print $NF}'`
V_LOADING_STATE=`cat hubei_CSMII_JK.log|grep LOADING|grep STATE|awk '{print $NF}'`
V_SELFTEST_STATE=`cat hubei_CSMII_JK.log|grep SELFTEST|grep STATE|awk '{print $NF}'`
V_TESTFLAG=`cat hubei_CSMII_JK.log|grep ESTFLAG|awk '{print $NF}'`
if [ ${v_SERVICE} == "OK" ] && [ ${v_ONLINE} == "YES" ]&& [ ${V_IOPORT} == "OK" ]&& [ ${V_ICP} == "OK" ]&& [ ${V_LOADING_STATE} == "LOADED" ]&& [ ${V_SELFTEST_STATE} == "TESTED" ]&& [ ${V_TESTFLAG} == "YES" ];
then
echo "正常"
else
#执行复位语句:reset-board:slot=5;\r\n
{
sleep 2
printf "hongjie\r\n"
sleep 2
printf "hongjie\r\n"
sleep 2
printf ":reset-board:slot=5;\r\n"
sleep 60
} | telnet 192.168.110.235 23 >> hubei_CSMII.log ;
fi
#将6.txt文本中按,分割,取出123列用|连起来
awk -F, '{print $1 "|" $2 "|" $3}' 6.txt
#打印6.txt文本第2列到最后一列
awk '{for(i=2;i<=NF;++i) printf $i "\t";printf "\n"}' 6.txt
#打印6.txt文本第2行到最后一行的数据
awk '{L[NR]=$0}END{for (i=2;i<=NR;i++){print L[i]}}' 6.txt
#打印6.txt文本的第1行第2列
awk 'NR==1{print $2}' 6.txt
#打印6.txt文本文件的总行数
awk 'END{print NR}' 6.txt
#打印6.txt文本第一行
awk 'NR==1{print}' 6.txt
###################################################################
#1.txt文本内容如下,列与列之间有空格
cat 1.txt
1 2 3 4 5
#现在需要实现:
1,2,3,4,5
cat 1.txt | awk '{print $1 "," $2 "," $3 "," $4"," $5}' >> 2.txt
从尾开始
cat 1.txt | awk '{print $1 "," $(NF-3) "," $(NF-2) "," $(NF-1) "," $NF }' >>3.txt