Telnet automation script
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........ |
clearly not an intro. moved to newbie.
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" |
Quote:
|
Again some more help.....
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... |
I mean how we can make decision from grep...
|
By testing it's result code ... it's 0 on success, 1 on failure.
Cheers, Tink |
How to check d result code sir. Can u please give me an example. or can we try like this.....
nmap -P0 -p110 1.2.3.4 > test.txt if [ grep -c open test.txt -eq 1 ] ; then goto next else create error . . . . . . |
Code:
if `grep -c open test.txt >/dev/null 2>&1` then 0 or to catpure the output of the grep in a variable and check that ... always more than one way to do it. ;} http://www.tldp.org/LDP/abs/html/index.html Cheers, Tink |
you'd do well to eliminate the text file, it's totally redundant...
if [ "$(nmap -P0 -p110 1.2.3.4 | grep open)" ] then ... fi |
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. Happy Times! |
well the point is expect is not a good tool for the job in the first place...
|
Quote:
|
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..... |
Chris, your idea is perfect i should not use that text file.....
Really great.. |
#!/bin/bash
clear sleep 1 if [ "$(nmap -P0 -p25 1.2.3.4 | grep open)" ] then echo SMTP is ok in 1.2.3.4 else echo SMTP problem in 1.2.3.4 fi sleep 1 if [ "$(nmap -P0 -p110 1.2.3.4 | grep open)" ] then echo POP is ok in 1.2.3.4 else echo POP problem in 1.2.3.4 fi ........................................................................... I checked. Its working perfectly. Thank you Chris,Tink,Hewson |
All times are GMT -5. The time now is 07:08 PM. |