Sir Arthur
04.06.2009, 11:10
Скрипт
cat /etc/mrtg/ipsec.sh
#!/usr/bin/perl -w
$file = "addr.txt";
open (InFile, "$file");
foreach $line (<InFile>)
{
PING="/bin/ping";
ADDR=$line;
DATA=`$PING -c4 -s500 $ADDR -q `;
LOSS=`echo $DATA | awk '{print $18 }' | tr -d %`;
echo $LOSS
if [ $LOSS = 100 ];
then
echo 0;
else
echo $DATA | awk -F/ '{print $5 }';
fi
};
close(InFile);
#original by GrayCat
файл входных параметров
cat /etc/mrtg/addr.txt
10.2.2.1
10.16.2.1
10.39.2.129
10.52.2.1
10.86.2.1
10.86.2.129
10.54.2.1
10.61.2.193
10.63.2.1
10.78.2.253
10.23.2.1
10.72.2.1
10.25.2.1
10.25.2.129
172.17.4.10
---------- Добавлено в 11:10 ---------- Предыдущее сообщение было написано в 11:03 ----------
ругается вот так
/etc/mrtg/ipsec.sh > result
Unquoted string "awk" may clash with future reserved word at /etc/mrtg/ipsec.sh line 18.
Unquoted string "fi" may clash with future reserved word at /etc/mrtg/ipsec.sh line 21.
Can't modify constant item in scalar assignment at /etc/mrtg/ipsec.sh line 9, near ""/bin/ping";"
syntax error at /etc/mrtg/ipsec.sh line 17, near "else"
syntax error at /etc/mrtg/ipsec.sh line 21, near "fi
}"
Execution of /etc/mrtg/ipsec.sh aborted due to compilation errors.
cat /etc/mrtg/ipsec.sh
#!/usr/bin/perl -w
$file = "addr.txt";
open (InFile, "$file");
foreach $line (<InFile>)
{
PING="/bin/ping";
ADDR=$line;
DATA=`$PING -c4 -s500 $ADDR -q `;
LOSS=`echo $DATA | awk '{print $18 }' | tr -d %`;
echo $LOSS
if [ $LOSS = 100 ];
then
echo 0;
else
echo $DATA | awk -F/ '{print $5 }';
fi
};
close(InFile);
#original by GrayCat
файл входных параметров
cat /etc/mrtg/addr.txt
10.2.2.1
10.16.2.1
10.39.2.129
10.52.2.1
10.86.2.1
10.86.2.129
10.54.2.1
10.61.2.193
10.63.2.1
10.78.2.253
10.23.2.1
10.72.2.1
10.25.2.1
10.25.2.129
172.17.4.10
---------- Добавлено в 11:10 ---------- Предыдущее сообщение было написано в 11:03 ----------
ругается вот так
/etc/mrtg/ipsec.sh > result
Unquoted string "awk" may clash with future reserved word at /etc/mrtg/ipsec.sh line 18.
Unquoted string "fi" may clash with future reserved word at /etc/mrtg/ipsec.sh line 21.
Can't modify constant item in scalar assignment at /etc/mrtg/ipsec.sh line 9, near ""/bin/ping";"
syntax error at /etc/mrtg/ipsec.sh line 17, near "else"
syntax error at /etc/mrtg/ipsec.sh line 21, near "fi
}"
Execution of /etc/mrtg/ipsec.sh aborted due to compilation errors.