浪笑流尘 2014-10-24 02:52 采纳率: 0%
浏览 2342

shell脚本执行异常,一直循环

脚本目的,分析脚本执行结果,将有问题的项目附加到结果后面。

#!/bin/bash

function analyse_report()
{
abnormal_item=$1
IP=$2
case "$abnormal_item" in
3)
echo "hostname of $IP">>Linux_1410221605.txt
cat ../result/1410231618/result_192.168.59.199/hostname.log >>Linux_1410221605.txt
;;
4)
echo "system_version of $IP">>Linux_1410221605.txt
cat ../result/1410231618/result_192.168.59.199/uname.log | awk '{print $3}'>>Linux_1410221605.txt
;;
5)
echo "disk_usage of $IP">>Linux_1410221605.txt
cat ../result/1410231618/result_192.168.59.199/df.log>>Linux_1410221605.txt
;;
6)
echo "CPU_usage of $IP">>Linux_1410221605.txt
cat ../result/1410231618/result_192.168.59.199/iostat.log>>Linux_1410221605.txt
;;
7)
echo "IO_usage of $IP">>Linux_1410221605.txt
cat ../result/1410231618/result_192.168.59.199/iostat.log >>Linux_1410221605.txt
;;
8)
echo "MEM_usage of $IP">>Linux_1410221605.txt
cat ../result/1410231618/result_192.168.59.199/free.log>>Linux_1410221605.txt
;;
9)
echo "SWAP_usage of $IP">>Linux_1410221605.txt
cat ../result/1410231618/result_192.168.59.199/free.log| >>Linux_1410221605.txt
;;
esac
}
echo "\n\n" >>Linux_1410221605.txt
echo "****************************The following is the abnormal items****************************\n" >>Linux_1410221605.txt
while read line
do
Result_line=echo $line |grep ^[[:digit:]]|grep "XX"
for((i=1;i<=7;i++))
do

Item_num=$[$i+2] >/dev/null 2>&1
IP=echo $Result_line | awk '{print $1}'
Result=echo $Result_line|tr -s [" "] [":"]|cut -d ":" -f $Item_num
if [ "$Result" == "--" ]
then
continue
else
analyse_report $Item_num $IP
fi
done

done < "Linux_1410221605.txt"

Linux_1410221605.txt格式
192.168.1.1 test -- -- XX -- -- -- -- 1410231700

脚本运行后,发现两个参数没有传递到function,而且程序一直循环,
没找到错误,求解!!! 不胜感激!

  • 写回答

1条回答

  • dncszp 2014-11-08 03:28
    关注

    Result_line=echo $line |grep ^[[:digit:]]|grep "XX"
    IP=echo $Result_line | awk '{print $1}'
    Result=echo $Result_line|tr -s [" "] [":"]|cut -d ":" -f $Item_num

    赋值要加``或$()

    Result_line=$(echo $line |grep ^[[:digit:]]|grep "XX")

    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 MATLAB动图问题
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名