1753860 Members
7866 Online
108809 Solutions
New Discussion юеВ

Script error

 
SOLVED
Go to solution
Adam W.
Valued Contributor

Script error

I found this script on one of the threads and thought it would be very usful to track the amount of data coming into my lan. However, I get the below error everytime I try to run it. Can someone help?

# vi lanaction.sh
"lanaction.sh" [Read only] 29 lines, 385 characters
#!/bin/ksh
#################################
# CURRENTLY IN PROGRESS
#
#
#
#################################


function lanad
{
lanadmin<< EOF >/tmp/t 2>&1
lan
display

quit
EOF
cat /tmp/t|grep Inbound|grep Oct|awk '{print $4}'
}
echo "Inbound Bytes per second on default lan interface"
let z=0
while true
do
sleep 1
let x=$(lanad)
let t=$x-$z
echo $t
let z=$x
done
:q!
# sh lanaction.sh
lanaction.sh[10]: Syntax error at line 12 : `<<' is not matched.
There are two types of people in the world, Marines and those who wish they were.
15 REPLIES 15
Dennis Handly
Acclaimed Contributor

Re: Script error

You have a space between the "<<" and "EOF"
Adam W.
Valued Contributor

Re: Script error

I removed the space but get the same error.
There are two types of people in the world, Marines and those who wish they were.
Dennis Handly
Acclaimed Contributor

Re: Script error

>but get the same error.

Is "EOF" in column 1?
OldSchool
Honored Contributor

Re: Script error

the E in the second EOF isn't the first character in the line??

you need:

lanadmin <.
...your stuff here..
.
EOF

NOTE: <<-EOF can be used if the second EOF is preceded by one (or more???) tabs

Re: Script error

That whole lanad function looks a bit "round the houses" to me - how about replacing it with something a little simpler:

function lanad
{
echo "lan\ndisplay\n\nquit" | lanadmin 2>&1 | awk '/Inbound Octets/ {print $4}'
}

HTH

Duncan

I am an HPE Employee
Accept or Kudo

Re: Script error

Incidentally another "problem" with this script is that it will only print stats for the "default" lan interface for lanadmin (which is defined as the first one you see when you run lanscan). That might not be the interface you are actually using...

HTH

Duncan

I am an HPE Employee
Accept or Kudo
Adam W.
Valued Contributor

Re: Script error

Duncan your suggestion worked wonderfully.

I am still a bit confused as to why the original doesn't work though. The second "EOF" is the first character in that line, so even though yours worked well duncan, I would still like to know where I messed up the first time.
There are two types of people in the world, Marines and those who wish they were.
Adam W.
Valued Contributor

Re: Script error

Also, Duncan, how would you suggest, getting this data for ALL lan interfaces?
There are two types of people in the world, Marines and those who wish they were.
OldSchool
Honored Contributor

Re: Script error

well...if you post the original as an attachment it would help, as the attachment won't mess with spacing like a regular post does.