쉘 스크립트 오류 좀 봐주세요 ㅠ
스크립트를 실행시키면 이런 문구가 뜨고요 ㅠ
(standard_in) 2: parse error
EOF encountered in a comment.
(standard_in) 2: parse error
EOF encountered in a comment.
./090-netperf.sh: line 23: / 100 : syntax error: operand expected (error token is "/ 100 ")
스크립트 내용을 보자면
아래와 같은데 왜 에러가 뜨는지 모르겠어요 ㅠ
101가지 예제로 정복하는 셸스크립트라는 책에 있는 문제 인데요
지금 쓰는 리눅스는 레드헷 9버젼이구요 ㅠ..
도와주세요
#!/bin/sh
# netperf - analyze the netstat running performance log, identifying important
# results and trends.
log="/var/log/netstat.log"
scriptbc="/usr/local/src/009-scriptbc.sh"
stats="/tmp/netperf.stats.$$"
awktmp="/tmp/netperf.awk.$$"
trap "/bin/rm -f $awktmp $stats" 0
if [ ! -r $log ] ; then
echo "Error: can't read netstat log file $log" >&2
exit 1
fi
# first, report the basic statistics of the latest entry in the log file...
eval $(tail -1 $log) # all values turn into shell variables
rep="$($scriptbc -p 3 $re/$snt\*100)"
repn="$($scriptbc -p 4 $re/$snt\*10000 | cut -d. -f1)"
repn="$(( $repn / 100 ))"
retop="$($scriptbc -p 3 $reto/$snt\*100)";
retopn="$($scriptbc -p 4 $reto/$snt\*10000 | cut -d. -f1)"
retopn="$(( $retopn / 100 ))"
dupp="$($scriptbc -p 3 $dup/$rec\*100)";
duppn="$($scriptbc -p 4 $dup/$rec\*10000 | cut -d. -f1)"
duppn="$(( $duppn / 100 ))"
oop="$($scriptbc -p 3 $oo/$rec\*100)";
oopn="$($scriptbc -p 4 $oo/$rec\*10000 | cut -d. -f1)"
oopn="$(( $oopn / 100 ))"
echo "Netstat is currently reporting the following:"
echo -n " $snt packets sent, with $re retransmits ($rep%) "
echo "and $reto retransmit timeouts ($retop%)"
echo -n " $rec packets received, with $dup dupes ($dupp%)"
echo " and $oo out of order ($oop%)"
echo " $creq total connection requests, of which $cacc were accepted"
echo ""
## now let's see if there are any important problems to flag
if [ $repn -ge 5 ] ; then
echo "*** Warning: Retransmits of >= 5% indicates a problem "
echo "(gateway or router flooded?)"
fi
if [ $retopn -ge 5 ] ; then
echo "*** Warning: Transmit timeouts of >= 5% indicates a problem "
echo "(gateway or router flooded?)"
fi
if [ $duppn -ge 5 ] ; then
echo "*** Warning: Duplicate receives of >= 5% indicates a problem "
echo "(probably on the other end)"
fi
if [ $oopn -ge 5 ] ; then
echo "*** Warning: Out of orders of >= 5% indicates a problem "
echo "(busy network or router/gateway flood)"
fi
# now let's look at some historical trends...
echo "analyzing trends...."
while read logline ; do
eval "$logline"
rep2="$($scriptbc -p 4 $re / $snt \* 10000 | cut -d. -f1)"
retop2="$($scriptbc -p 4 $reto / $snt \* 10000 | cut -d. -f1)"
dupp2="$($scriptbc -p 4 $dup / $rec \* 10000 | cut -d. -f1)"
oop2="$($scriptbc -p 4 $oo / $rec \* 10000 | cut -d. -f1)"
echo "$rep2 $retop2 $dupp2 $oop2" >> $stats
done < $log
echo ""
# now calculate some statistics, and compare them to the current values
cat << "EOF" > $awktmp
{ rep += $1; retop += $2; dupp += $3; oop += $4 }
END { rep /= 100; retop /= 100; dupp /= 100; oop /= 100;
print "reps="int(rep/NR) ";retops=" int(retop/NR) \
";dupps=" int(dupp/NR) ";oops="int(oop/NR) }
EOF
eval $(awk -f $awktmp < $stats)
if [ $repn -gt $reps ] ; then
echo "*** Warning: Retransmit rate is currently higher than average."
echo " (average is $reps% and current is $repn%)"
fi
if [ $retopn -gt $retops ] ; then
echo "*** Warning: Transmit timeouts are currently higher than average."
echo " (average is $retops% and current is $retopn%)"
fi
if [ $duppn -gt $dupps ] ; then
echo "*** Warning: Duplicate receives are currently higher than average."
echo " (average is $dupps% and current is $duppn%)"
fi
if [ $oopn -gt $oops ] ; then
echo "*** Warning: Out of orders are currently higher than average."
echo " (average is $oops% and current is $oopn%)"
fi
echo \(analyzed $(wc -l < $stats) netstat log entries for calculations\)
exit 0
이렇게 되는데...
그냥 변수를 나눗셈하는 것은 안 되고
eval같은 함수를 통해 계산을 하게 해야하지 않나요? 그런데 쉘 스크립트에 eval이 있었나...?
하여간 쉘 내장 함수든 외부 실행파일이든 ($repn / 100) 이 구문 대신 eval("$repn / 100") 식으로 수식 계산을 시켜야 할 겁니다.
---------- 시그 *****
저도 세벌식을 씁니다.
M$윈도우즈, 리눅스, 맥 오에스 텐, 맥 오에스 클래식을 모두 엔드유저 수준으로 쓴답니다.
http://psg9.egloos.com
=================
잠못자는 한솔아빠
$(( )) 처럼 하면 안의
$(( )) 처럼 하면 안의 내용을 수식으로 계산하게 됩니다.
따라서 이 부분은 에러가 아니고요..
EOF encountered in a comment.
라는 에러를 봐서는 뭔가 파일이 저장된 형태에 문제가 있는듯..
윈도우즈에서 작성한 경우
윈도우즈에서 작성했다면 개행 문자 처리때문에 에러가 발생할 수도 있습니다.
댓글 달기