1827896 Members
1592 Online
109969 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.
Solution

Re: Script error

For all lan interfaces? Something quick and dirty like this?

#!/usr/bin/sh
lanscan -p | while read ppa
do
z[${ppa}]=$(lanadmin -g mibstats ${ppa} 2>&1 | awk '/Inbound Octets/ {print $4}')
done
echo "Inbound Bytes per second on all lan interfaces"
while true
do
sleep 1
lanscan -p | while read ppa
do
x[${ppa}]=$(lanadmin -g mibstats ${ppa} 2>&1 | awk '/Inbound Octets/ {print $4}')
(( t=${x[${ppa}]} - ${z[${ppa}]} ))
echo "lan${ppa}\t${t}"
z[${ppa}]=${x[${ppa}]}
done
done

What are you hoping to see from this data? Inbound octets don't tell you much about any particular interface...

HTH

Duncan

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

Re: Script error

Got it old school.
There are two types of people in the world, Marines and those who wish they were.
Adam W.
Valued Contributor

Re: Script error

Thanks Duncan that works very well, really I am just "messing around" to see what can be done, and have a little fun with it. Just interesting to know how much is coming in is all.
There are two types of people in the world, Marines and those who wish they were.
OldSchool
Honored Contributor

Re: Script error

Adam,

for what its worth, the script you attached did not generate the syntax errors you reported....so i've got nothin for you
Dennis Handly
Acclaimed Contributor

Re: Script error

>ME: You have a space between the "<<" and "EOF"

I found this space doesn't matter. But in the other place it matters.
Adam W.
Valued Contributor

Re: Script error

Well Old School, I still get the error. I will figure something out. Thanks Guys! I appreciate your help
There are two types of people in the world, Marines and those who wish they were.