The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
oracle connection from shell script DILEEP410 Shell Programming and Scripting 4 07-01-2009 02:19 AM
sybase connection through shell-script Amitabh UNIX for Dummies Questions & Answers 9 04-10-2009 10:34 PM
Connection to database through shell script ravi214u Shell Programming and Scripting 1 01-08-2009 05:44 PM
status bar in shell script or perl learnbash Shell Programming and Scripting 2 11-16-2008 11:17 AM
Telnet script to test open ports on mult servers liketheshell Shell Programming and Scripting 2 02-15-2008 12:13 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-19-2009
yhcheong yhcheong is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 9
Exclamation How to Create a shell script to test the telnet connection status

Hi friends,

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 !
  #2 (permalink)  
Old 03-19-2009
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,422
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.
  #3 (permalink)  
Old 03-19-2009
yhcheong yhcheong is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 9
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
  #4 (permalink)  
Old 03-19-2009
pludi's Avatar
pludi pludi is online now Forum Staff  
Moderator
  
 

Join Date: Dec 2008
Location: .at
Posts: 1,788
nmap isn't quite that useful to test connections. You could install netcat and test the connection using the -z switch, eg
Code:
netcat -z ${MACHINE} 23
if [ $? -eq 0 ]
then
    echo "Telnet accepting connections"
else
    echo "Telnet connections not possible"
fi
Or, if you have bash available and don't want to install anything else you could try replacing the netcat call with
Code:
exec 3>/dev/tcp/${MACHINE}/23
But this is really, really fugly.
  #5 (permalink)  
Old 03-19-2009
yhcheong yhcheong is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 9
Hi Pludi,

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!
  #6 (permalink)  
Old 03-19-2009
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,422
what version is your sun solaris OS?
  #7 (permalink)  
Old 03-19-2009
pludi's Avatar
pludi pludi is online now Forum Staff  
Moderator
  
 

Join Date: Dec 2008
Location: .at
Posts: 1,788
Please use [code ][/code] (sans the space) tags for source and listings, it's easier to read.
Quote:
Originally Posted by yhcheong View Post
Code:
exec 3>/dev/tcp/${10.x.x.x}/2071
if [ $? -eq 0 ]
then
    echo "Telnet accepting connections"
else
    echo "Telnet connections not possible"
fi
bash: /dev/tcp/${10.x.x.x}/2071: bad substitution.
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
Code:
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
Sponsored Links
Closed Thread

Bookmarks

Tags
grep or

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 02:50 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0