The UNIX and Linux Forums  

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 03:19 AM
sybase connection through shell-script Amitabh UNIX for Dummies Questions & Answers 9 04-10-2009 11: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 Bulgarian Greek Powered by Powered by Google
 
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
Quote:
Originally Posted by ghostdog74 View Post
what version is your sun solaris OS?
The version is

SunOS 5.8 Generic_117350-38 sun4u sparc SUNW,Sun-Fire-V890
  #2 (permalink)  
Old 03-19-2009
pludi's Avatar
pludi pludi is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2008
Location: .at
Posts: 1,900
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
  #3 (permalink)  
Old 03-19-2009
yhcheong yhcheong is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 9
Quote:
Originally Posted by pludi View Post
Please use [code ][/code] (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
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


Hi,
Code:
MACHINE=10.2.191.100 
MACHINE=10.1.101.100 
MACHINE=10.3.181.100 
exec 3>/dev/tcp/${MACHINE}:2061
if [ $? -eq 0 ]
then
    echo "Telnet accepting connections"
else
    echo "Telnet connections not possible"
fi
and the result is below

Code:
bash-2.03$ MACHINE=10.2.191.100
bash-2.03$ MACHINE=10.1.101.100
bash-2.03$ MACHINE=10.3.181.100
bash-2.03$ exec 3>/dev/tcp/${MACHINE}:2061
bash: /dev/tcp/10.3.181.100:2061: Not a directory
bash-2.03$ if [ $? -eq 0 ]
> then
>     echo "Telnet accepting connections"
> else
>     echo "Telnet connections not possible"
> fi
Telnet connections not possible
Sorry, please guide me.
Many Thanks
  #4 (permalink)  
Old 03-19-2009
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,553
not guaranteed to work, but you can try
Code:
# sleep 3 | telnet somewhere portnumer
use grep or awk to grab messages to confirm connection or refusal
  #5 (permalink)  
Old 03-19-2009
pludi's Avatar
pludi pludi is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2008
Location: .at
Posts: 1,900
Quote:
Originally Posted by yhcheong View Post
Code:
MACHINE=10.2.191.100 
MACHINE=10.1.101.100 
MACHINE=10.3.181.100 
exec 3>/dev/tcp/${MACHINE}/2061
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.
Code:
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
  #6 (permalink)  
Old 03-19-2009
pludi's Avatar
pludi pludi is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2008
Location: .at
Posts: 1,900
/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.
  #7 (permalink)  
Old 03-19-2009
yhcheong yhcheong is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 9
Quote:
Originally Posted by pludi View Post
/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.
I have check the the directory under dev. The TCP is exist. Hmm, any idea other than bash?
THanks!
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 11:47 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
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