1752848 Members
3557 Online
108789 Solutions
New Discussion

Re: Shell Scripting

 
Jayant Butte
Occasional Contributor

Shell Scripting

Hello,
I am required to write a shell script for checking port availabilty. I am using telnet in the script. Can you tell me how I can send the escape sequence ^] in the script, to come to the command mode. I need to do this to run the status command at the telnet prompt.
What I have done is something like this:
------------------------------
while true

do
telnet << EOF
open hostname port
???? ^]
status >> filename
close
EOF
done
------------------------------
Thanks

Jayant
1 REPLY 1
Marco Paganini
Respected Contributor

Re: Shell Scripting

Hello

In my opinion, shell scripts are a bad tool for your job. You may want to write a small perl program to open a socket to the desired port. If you really don't want to write a program, you cake nmap (http://hpux.ee.ualberta.ca/hppd/hpux/Networking/Admin/nmap-2.53/) to do the job for you like this:

(suppose you want to test port 22 on host sshhost)

if
nmap sshhost -p 22 | grep -i '22/tcp.*open' >/dev/null 2>&1; then
echo Port is open
else
echo Port is closed
fi

Shameless plug: You may try a small perl monitoring tool I wrote to monitor ports and other services at http://www.paganini.net/angel

Hope it helps,
Paga
Keeping alive, until I die.