쉘 스크립트 오류 좀 봐주세요 ㅠ

minimon@kldp.org의 이미지

스크립트를 실행시키면 이런 문구가 뜨고요 ㅠ

(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

이렇게 되는데...

hayarobi의 이미지

eval같은 함수를 통해 계산을 하게 해야하지 않나요? 그런데 쉘 스크립트에 eval이 있었나...?
하여간 쉘 내장 함수든 외부 실행파일이든 ($repn / 100) 이 구문 대신 eval("$repn / 100") 식으로 수식 계산을 시켜야 할 겁니다.

---------- 시그 *****
저도 세벌식을 씁니다.
M$윈도우즈, 리눅스, 맥 오에스 텐, 맥 오에스 클래식을 모두 엔드유저 수준으로 쓴답니다.
http://psg9.egloos.com

=================
잠못자는 한솔아빠

auditory의 이미지


$(( )) 처럼 하면 안의 내용을 수식으로 계산하게 됩니다.
따라서 이 부분은 에러가 아니고요..

EOF encountered in a comment.

라는 에러를 봐서는 뭔가 파일이 저장된 형태에 문제가 있는듯..

pcharley의 이미지

윈도우즈에서 작성했다면 개행 문자 처리때문에 에러가 발생할 수도 있습니다.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.