ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
I haven't used the ksh shell, but it probably has a similar job control feature. "$!" is the last background process. I'm using a double negative. If the port is open, killing the last background process fails.
I tested the scipt and it is rather slow internally. It seems as though it is taking a couple of seconds to determine whether or not the device is up or not(timing out). It there anyway to shorten the length of time it takes to access the device and determine whether or not telnet port 23 is open. thanks
I am willing to try your one liner perl script but will it produce the output that I am looking for?
PHP Code:
$ cat check.ksh #!/bin/ksh exec 2>/dev/null printf " %-20.20s %-8s %-6s\n" host status telnet for host in $(<list) do status=down telnet=closed if ping $host 5 >/dev/null 2>&1 then status=up read foo < /dev/tcp/$host/23 && telnet=open else telnet="n/a" fi printf " %-20.20s %-8s %-6s\n" $host $status $telnet done $ ./check.ksh host status telnet 127.0.0.1 up closed 192.168.1.1 up open 192.168.1.2 up closed 192.168.1.3 down n/a
Telnet connection timeout is too high. You can use telnet command on any host and you'll see that if the host is up, telnet will need at least a minute to respond that the service in unavailable.
telnet google.com is now running maybe for 4 minutes and still hasn't finished
Last edited by Alien_Hominid; 11-28-2007 at 08:02 AM.
no, becuase telnet as a client will retry, generally do an exponentially timed backoff between attempts and such. nmap will send one SYN packet, expect one SYNACK back within a few milliseconds
I promise I wont ask for anymore help but how can I have this script:
PHP Code:
$ cat check.ksh #!/bin/ksh exec 2>/dev/null printf " %-20.20s %-8s %-6s\n" host status telnet for host in $(<list) do status=down telnet=closed if ping $host 5 >/dev/null 2>&1 then status=up read foo < /dev/tcp/$host/23 && telnet=open else telnet="n/a" fi printf " %-20.20s %-8s %-6s\n" $host $status $telnet done $ ./check.ksh host status telnet 127.0.0.1 up closed 192.168.1.1 up open 192.168.1.2 up closed 192.168.1.3 down n/a
to include the hostname of the device and have two different categories of devices like NAM's and Sniffers. like for example:
PHP Code:
NAM status telnet 127.0.0.1 up closed 192.168.1.1 up open 192.168.1.2 up closed 192.168.1.3 down n/a
Sniffers status telnet 127.0.0.1 up closed 192.168.1.1 up open 192.168.1.2 up closed 192.168.1.3 down n/a
help
Last edited by metallica1973; 11-28-2007 at 12:01 PM.
Op mentioned he can't use nmap and I don't know how perl or /dev/tcp/$host/23 peform their checks. Sorry for misinformation then. Based my opinion on that that all need several minutes to respond.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.