I'm newbie to shell script. I wanted to create a shell script which able to write a result for all the telnet connection status. For example, from this machine I want to test the telnet connection (total 100+ servers) with this machine.
Any idea how to write this shell script?
Appreciate if you guys could help on this.
Thanks !
if you have Python, you can use the script here. the Python script tests for ports. For telnet, just substitute with 23. other solutions include using nmap.
Thanks for the feedback.
The current machine is running on sun solaris OS, it does not has python. The script I want to test is test the telnet connection with other 100+ machines. Is there any shell script?
The nmap seems like I need to install on the server.
Thanks in advance
Thanks for the suggestion, if running bash. I think it is same by executing below command
for one by one(since I have hundred over telnet connection). The telnet connection port is
2071
% telnet 10.x.x.x 2071
for the bash command
exec 3>/dev/tcp/${10.x.x.x}/2071
if [ $? -eq 0 ]
then
echo "Telnet accepting connections"
else
echo "Telnet connections not possible"
fi
It seems like not working.
bash: /dev/tcp/${10.x.x.x}/2071: bad substitution.
Do you have any idea which can lead me to run the script in one shot, and the output is the hundred over telnet connection status. THanks in advance!
Please use (sans the space) tags for source and listings, it's easier to read.
The ${MACHINE} that I used was in preparation for the loop that you'll need for that many machines (it's substituted by the value of the variable MACHINE)
Change it like this and try again
MACHINE=10.0.0.1 # Change to what ever you need
exec 3>/dev/tcp/${MACHINE}/2071
if [ $? -eq 0 ]
then
echo "Telnet accepting connections"
else
echo "Telnet connections not possible"
fi
If you copy and paste, do so correctly. It's /dev/tcp/<machine>/<port>. The seperator is always the forward slash.
And you might want to start with some basic texts about shell programming, because that is not how you construct a loop (except maybe if you can create a DWIMTD function). There's a good introduction available here. It's written for Linux, but there are very few specific things used, most applies to any platform that bash runs on.
MACHINES="10.2.191.100 10.1.101.100 10.3.181.100"
for MACHINE in ${MACHINES}
do
exec 3>/dev/tcp/${MACHINE}/2061
if [ $? -eq 0 ]
then
echo "${MACHINE}: Telnet accepting connections"
else
echo "${MACHINE}: Telnet connections not possible"
fi
done
Thanks for the guide. But it seems like this line of the code not functioning.
exec 3>/dev/tcp/${MACHINE}/2061
When I check the dev/TCP, it isn't a directory. I've execute the shell code, but the error prompt as below:
bash-2.03$
bash-2.03$ MACHINES="10.97.124.100 10.12.44.10"
bash-2.03$ for MACHINE in ${MACHINES}
> do
> exec 3>/dev/tcp/${MACHINE}/2061
> if [ $? -eq 0 ]
> then
> echo "${MACHINE}: Telnet accepting connections"
> else
> echo "${MACHINE}: Telnet connections not possible"
> fi
> done
bash: /dev/tcp/10.97.124.100/2061: Not a directory
10.67.170.100: Telnet connections not possible
bash: /dev/tcp/10.12.44.10/2061: Not a directory
/dev/tcp/... isn't a directory on any UNIX system that I know of, but a hint for bash to open a TCP connection and use it as a file handle. If bash complains about it that probably means that this functionality isn't supported.
Yes, it does exist, but I guess is not supported. The only solution is to install the netcat on the sun solaris?
Thanks for the suggestion, but I hope there will be an alternate solution for me.