LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   script for telnet (https://www.linuxquestions.org/questions/programming-9/script-for-telnet-821393/)

packets 07-21-2010 11:34 PM

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?

zordrak 07-22-2010 05:07 AM

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

http://nc110.sourceforge.net/
http://en.wikipedia.org/wiki/Expect

packets 07-22-2010 07:25 PM

@zordrak

Thanks for the suggestions. It seems netcat is a promising tool. Will try these and inform you about the outcome.

ghostdog74 07-22-2010 08:40 PM

Quote:

Originally Posted by packets (Post 4041434)
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

packets 07-22-2010 08:49 PM

@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

ghostdog74 07-22-2010 08:59 PM

Quote:

Originally Posted by packets (Post 4042521)
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.


All times are GMT -5. The time now is 09:13 AM.