Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi
my work is server monitoring. Simply by using telnet i will check particular server's port is open or not.This is a primary test.for example,
telnet 1.2.3.4 25(port 25)
I have to check more than 20 servers frequently.
I wrote a script simply which automated my work partially.
But if we use 'expect' we can automate this fully. But i cant get much help about 'expect'. Can anyone help me in completing this script? Please........
as for your issue, telnet is fine for manual checking, but not for automating it really, as you can't nicely control what telnet does. Expect is for controlling the flow of otherwise manual commands, but there are no manual commands in this test. instead just use a tool like nmap - "nmap -P0 -p25 1.2.3.4"
Last edited by acid_kewpie; 11-19-2007 at 02:17 AM.
as for your issue, telnet is fine for manual checking, but not for automating it really, as you can't nicely control what telnet does. Expect is for controlling the flow of otherwise manual commands, but there are no manual commands in this test. instead just use a tool like nmap - "nmap -P0 -p25 1.2.3.4"
Thank u very much sir for this fast reply. now i am in home(no linux mechine)Tonight i will check n try to finish the script using nmap. I wont forget your help. Thanks again
As per your advise i am going to use 'nmap -P0 -p25 1.2.3.4' in my script.
my script will b in the form of..
#!/bin/bash
flag=0 #i am introducing a flag
nmap -P0 -p110 1.2.3.4 > test.txt #directing op to a file
grep open test.txt #checking this file is having a
word 'open'
#if yes, no problem can go to
next server check dont modify flag
#Else have to create an error msg
n goto next server n make flag to 1
This is my logic. How can i use if. I mean how to give condition? Please help me...
That's one option. The other possibilities are to check $? for
0 or to catpure the output of the grep in a variable and check
that ... always more than one way to do it. ;}
In the future, you may find using TCL (or Python) to do the variable testing is a little easier than using BASH.
Classic Expect is built on top of TCL. There are many resources for TCL.
There is a singular book on Expect itself Exploring Expect [google.com].
I spend a great deal of time automating. I am not a fan of TCL. Thankfully Noah Spurrier has blessed us with Pexpect [sourceforge.net], a pure python expect package for Python.
well when tcl is the only tool you have it *can* be kinda cute. I end up doing a reasonable amount of tcl within our F5 load balancers, and the more i use it the less i totally hate it...
#!/bin/bash
clear
sleep 1
nmap -P0 -p25 1.2.3.4 > test.txt
if grep -q open test.txt; then
echo SMTP is ok in 1.2.3.4
else
echo SMTP problem in 1.2.3.4
fi
sleep 1
nmap -P0 -p110 1.2.3.4 > test.txt
if grep -q open test.txt; then
echo POP is ok in 1.2.3.4
else
echo POP problem in 1.2.3.4
fi
.........................................................................
Finally With your valuable help, I finished like this. Now we can check for even 1000 servers.
My next step is to send a mail to a person if particular port is not open in any server. Can we do that from command line itself? I think we have to add in else part.....
Last edited by senthilvael; 11-19-2007 at 04:04 PM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.