0

我有个问题。我需要显示一段时间的回声,我使用两个回声,第一个工作,但第二个它给出错误。

#!/bin/bash
conexiuni="/tmp/conexiuni"
if [ "$1" != "" ]; then
netstat -tuan | grep $1 | grep ESTAB | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n > $conexiuni
else
netstat -tuan  | grep ESTAB | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n > $conexiuni
fi

cat $conexiuni | while read line
do
  con=`echo ''$line'' | awk '{print $1}'`
  ip=`echo ''$line'' | awk '{print $2}'`
  if [ "$con" -gt "4" ]; then
       `echo -e "$ip" >> /var/log/drop_sc_ip`
       `echo -e "$ip"`
  fi
done
if [  -f "$conexiuni" ];
then
    `rm -rf $conexiuni`
fi

错误是:

./show_conn: line 15: 8.97.80.2: command not found
./show_conn: line 15: 8.76.109.13: command not found
./show_conn: line 15: 8.33.15.2: command not found
./show_conn: line 15: 9.118.226.3: command not found
4

1 回答 1

1

您可以在没有反引号的情况下编写此部分:

if [ "$con" -gt "4" ]; then
       echo -e "$ip" >> /var/log/drop_sc_ip
       echo -e "$ip"
fi

这部分也一样:

rm -rf $conexiuni

对于反引号,它首先执行反引号内的内容,然后尝试执行反引号的输出。

并更改循环:

while read con ip
do
    if [ "$con" -gt "4" ]; then
       echo -e "$ip" >> /var/log/drop_sc_ip
       echo -e "$ip"
    fi
done < $conexiuni
于 2013-07-16T00:30:31.470 回答