Results 1 to 3 of 3
i need some help with telnet access thru bas script. The problem came when
its run the netgear switch till its access the CLI
telnet> Trying 172.16.x.x...
Connected to 172.16.x.x.
...
- 06-05-2007 #1Just Joined!
- Join Date
- Jun 2007
- Posts
- 2
Netgear 7312-Bash Script
i need some help with telnet access thru bas script. The problem came when
its run the netgear switch till its access the CLI
telnet> Trying 172.16.x.x...
Connected to 172.16.x.x.
Escape character is '^]'.
(GSM7312)
User:
then after 5 second..
User:Connection closed by foreign host.
coding....
host=172.16.x.x
port=23
UserName=Sharkma
PassWord=pass
#cmd="ls /tmp"
timeout=3
file=file1
prompt="$"
(echo open ${host} ${port}
sleep 1
tout=${timeout}
while [ "${tout}" -ge 0 ]
do
if tail -1 "${file}" 2>/dev/null | egrep -v "UserName:" > /dev/null
then
echo "${UserName}"
sleep 1
tout=-5
continue
else
sleep 1
tout=`expr ${tout} - 1`
fi
done
if [ "${tout}" -ne "-5" ]; then
exit 1
fi
tout=${timeout}
while [ "${tout}" -ge 0 ]
do
if tail -1 "${file}" 2>/dev/null | egrep -v "PassWord:" > /dev/null
then
echo "${PassWord}"
sleep 1
tout=-5
continue
else
if tail -1 "${file}" 2>/dev/null | egrep -v "${prompt}" > /dev/null
then
tout=-5
else
sleep 1
tout=`expr ${tout} - 1`
fi
fi
done
if [ "${tout}" -ne "-5" ]; then
exit 1
fi
> ${file}
#echo ${cmd}
sleep 1
echo exit) | telnet
or someone have da better solution..
please help me...
- 06-05-2007 #2
Don't you think it would be easier to use Perl with the Net::Telnet module?
Or if you don't want to use perl you could use expect/tcl. Shell scripting just isn't the right choice for what you are trying to accomplish.
Net::Telnet:
Net::Telnet - interact with TELNET port or other TCP ports - search.cpan.org
Expect:
Tcl/Tk - What is Expect? Why use it?
Using Expect
- 06-06-2007 #3Just Joined!
- Join Date
- Jun 2007
- Posts
- 2
still da prob..but learn process up..up da way
for ur info..this is my task to fullfill my practical...
im poor in programming n linux..im keep trying to improve my skill..
hopely i can achieve something to grap..
so da solution
learn tcl/tk..and perl..
thanx


Reply With Quote