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
Script to telnet web server bsddaemon Shell Programming and Scripting 5 12-03-2008 06:30 AM
COuld not telnet but server powered tjsingh SCO 0 06-11-2008 05:53 AM
Cannot login via telnet or ssh to AIX 5.2 server pdtak UNIX for Advanced & Expert Users 5 04-10-2008 06:16 PM
I access to my server via Telnet SENG UNIX for Advanced & Expert Users 4 09-20-2006 02:21 AM
Telnet Server avd UNIX for Dummies Questions & Answers 4 08-17-2005 11:43 PM

Reply
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 07-05-2009
cesarNZ cesarNZ is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 70
telnet to another server

hi all,
i wanted to write a ksh script to telnet to another server on a particular port every 5 mins in order to send out an alert if that server went down.

how do i read the response that comes back when the server is down i.e "telnet: Unable to connect to remote host: Connection refused"


ta.
  #2 (permalink)  
Old 07-05-2009
vidyadhar85's Avatar
vidyadhar85 vidyadhar85 is offline Forum Staff  
Moderator(The Tutor)
  
 

Join Date: Jun 2008
Location: INDIA
Posts: 1,414
redirect the errors of the telnet to a file the grep for errors
If found display the appropriate error....
  #3 (permalink)  
Old 07-05-2009
cesarNZ cesarNZ is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 70
Quote:
Originally Posted by vidyadhar85 View Post
redirect the errors of the telnet to a file the grep for errors
If found display the appropriate error....
hey thanks for the reply, just came to mind that a telnet session if left open will get automatically shut/closed by the network. is there a better way of doing this rather than using telnet ??


ta.
  #4 (permalink)  
Old 07-05-2009
vidyadhar85's Avatar
vidyadhar85 vidyadhar85 is offline Forum Staff  
Moderator(The Tutor)
  
 

Join Date: Jun 2008
Location: INDIA
Posts: 1,414
you can use ping or an ftp session...
  #5 (permalink)  
Old 07-05-2009
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,958
Quote:
Originally Posted by vidyadhar85 View Post
you can use ping or an ftp session...
telnet and ftp uses different port, when telnetd is running, there is no guarantee that ftpd should be running or vice versa,
so ping on a telnet port is another alternative
  #6 (permalink)  
Old 07-06-2009
kshji's Avatar
kshji kshji is offline
Registered User
  
 

Join Date: Jun 2009
Location: Finland
Posts: 236
Ex. ping is not service test. If you like to test some tcp/ip service, use that service = only correct method to check service.
And use ip and port/service number - test only service, not own dns, ...
Create socket ex. socket.sh 111.111.111.111 23

Code:
#!/usr/bin/ksh
host=$1
port=$2
exec 4<>/dev/tcp/$host/$port
exit $?

Using that nice ksh93 script, you can do something like (check.sh):

Code:
#!/usr/bin/ksh
ip=$1
port=$2
waittime=$3
while true 
do
        ./socket.sh  "$ip" "$port"  ||  ./not_ok.sh "$ip" "$port"
        sleep $waittime
done


Code:
chmod a+rx *.sh
# ex. port 23 = usually telnet, wait 300 s
./check.sh  xx.xxx.xxx.xx  23 300 >> telnet.log 2>&1     &

Now you can write your not_ok.sh script as you like.

Last edited by kshji; 07-06-2009 at 02:32 AM..
Reply

Bookmarks

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 05:17 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