LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-21-2010, 11:34 PM   #1
packets
Member
 
Registered: Oct 2005
Posts: 339

Rep: Reputation: 32
script for telnet


I want to create script wherein it will check the application if its running. The command that I'll be using to check the application is telnet (if you can recommend others, that's ok).

I've an application and it is listening to port 1808. If I do telnet localhost 1808, the response is :
Code:
[root@test ~]# telnet localhost 1808
Trying 127.0.0.1...
telnet: connect to address 127.0.0.1: Connection refused
What I want to happen is if the response is like to code above, it will execute a commands. Obviously, above code knows that the application is not working so I need to execute a commands. I created a script before using expect but I don't think it will work because I haven't establish a shell yet unlike successful telnet I could spawn expect.

Any advise from a guru here?
 
Old 07-22-2010, 05:07 AM   #2
zordrak
Member
 
Registered: Feb 2008
Distribution: Slackware
Posts: 595

Rep: Reputation: 116Reputation: 116
I would instead recommend using netcat and then driving it with an expect script:

http://nc110.sourceforge.net/
http://en.wikipedia.org/wiki/Expect
 
Old 07-22-2010, 07:25 PM   #3
packets
Member
 
Registered: Oct 2005
Posts: 339

Original Poster
Rep: Reputation: 32
@zordrak

Thanks for the suggestions. It seems netcat is a promising tool. Will try these and inform you about the outcome.
 
Old 07-22-2010, 08:40 PM   #4
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by packets View Post
I want to create script wherein it will check the application if its running. The command that I'll be using to check the application is telnet (if you can recommend others, that's ok).

I've an application and it is listening to port 1808. If I do telnet localhost 1808, the response is :
Code:
[root@test ~]# telnet localhost 1808
Trying 127.0.0.1...
telnet: connect to address 127.0.0.1: Connection refused
What I want to happen is if the response is like to code above, it will execute a commands. Obviously, above code knows that the application is not working so I need to execute a commands. I created a script before using expect but I don't think it will work because I haven't establish a shell yet unlike successful telnet I could spawn expect.

Any advise from a guru here?
you can use nmap. Or if you have Perl/Python, you can whip up your own socket/port monitoring. Here's an example in Python
 
Old 07-22-2010, 08:49 PM   #5
packets
Member
 
Registered: Oct 2005
Posts: 339

Original Poster
Rep: Reputation: 32
@ghostdog74

Thanks for this link. It seems this is the one that I'm looking for. Though I need to study a bit of python to customize this scripts
 
Old 07-22-2010, 08:59 PM   #6
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by packets View Post
Though I need to study a bit of python to customize this scripts
it doesn't have to be Python, if you already know some other language that provides socket modules, you can use them. (eg Perl, Java, C, etc). the basics behind is just making a socket connection to the remote, and waiting for reply.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
telnet -> use contrl-D to exit using python telnet script athreyavc Programming 5 07-06-2009 11:17 PM
telnet script khodeir Programming 3 06-04-2009 03:18 PM
telnet script 91change Programming 6 08-28-2008 01:10 AM
Running Telnet in a script, want to save Telnet output, howtodothis??? anil3 Linux - Software 2 03-08-2006 04:01 PM
Telnet script pirra Programming 1 12-29-2004 03:04 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:20 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration