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.
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789
Rep:
Quote:
Originally Posted by metallica1973
I promise I wont ask for anymore help but how can I have this script:
[php... [/php]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
I see in your example neither the hostname nor two different categories as both lists have the same IPs.
Anyway, for the first request, just run the script twice with a different set of adresses. For adding the hostnames, that may depend on what naming service is in use on your WAN. (plain files, DNS, NIS, LDAP, ...).
That is just an example. Can I have this script not only ping the ip address from the namlist file which only has ip addresses and not hostnames(to many)but also include what the hostnames are by using better logic? for example when I perform ping -a using windows it will return the hostname of the device.In other words can we modify the script so that when it pings it will also include the hostname but truncates it to only to 6 characters if it is to long to keep the formating neat from the ip address from the namlist file and vice versa from the snifflist file(it only has host names, no ip address - the reason is that the ip address change and the hostnames are permanent). I see that we will have to use nslookup to get the hostname from devices!
PHP Code:
#!/bin/ksh exec 2>/dev/null printf " %-20.20s %-8s %-6s\n" NAM Status Telnet echo "=====================================" for NAM in $(<namlist) do status=down telnet=closed if ping $NAM 5 >/dev/null 2>&1 then status=up read foo < /dev/tcp/$NAM/23 && telnet=open else telnet="n/a" fi printf " %-20.20s %-8s %-6s\n" $NAM $Status $Telnet
done
echo
exec 2>/dev/null printf " %-20.20s %-8s %-6s\n" SNIFFERS Status Telnet echo "=====================================" for SNIFFERS in $(<snifflist) do status=down telnet=closed if ping $SNIFFERS 5 >/dev/null 2>&1 then status=up read foo < /dev/tcp/$SNIFFERS/23 && telnet=open else telnet="n/a" fi printf " %-20.20s %-8s %-6s\n" $SNIFFERS $Status $Telnet done
and have it look like this:
PHP Code:
NAM HOSTNAME Status Telnet Sniffers HOSTNAME Status Telnet 127.0.0.1 Localhost up closed 192.168.16.4 s00cbbd up closed 192.168.1.1 NAM1 up open 192.168.16.5 s00cbbf up open 192.168.1.2 NAM2 up closed 192.168.16.6 s00cbbg up closed 192.168.1.3 NAM3 down n/a 192.168.16.7 s00cbbj down n/a
Last edited by metallica1973; 11-29-2007 at 08:30 AM.
for NAM in $(<namlist) do status=down telnet=closed if ping $NAM 5 >/dev/null 2>&1 then status=up read foo < /dev/tcp/$NAM/23 && telnet=open else telnet="n/a" fi printf " %-20.20s %-8s %-6s\n" $NAM $status $telnet
done
echo
exec 2>/dev/null printf " %-20.20s %-8s %-6s\n" SNIFFERS Status Telnet echo "=====================================" for SNIFFERS in $(<snifflist) do status=down telnet=closed if ping $SNIFFERS 5 >/dev/null 2>&1 then status=up read foo < /dev/tcp/$SNIFFERS/23 && telnet=open else telnet="n/a" fi printf " %-20.20s %-8s %-6s\n" $SNIFFERS $Status $Telnet done
and have the formating like
PHP Code:
NAM HOSTNAME Status Telnet Sniffers HOSTNAME Status Telnet 127.0.0.1 Localhost up closed 192.168.16.4 s00cbbd up closed 192.168.1.1 NAM1 up open 192.168.16.5 s00cbbf up open 192.168.1.2 NAM2 up closed 192.168.16.6 s00cbbg up closed 192.168.1.3 NAM3 down n/a 192.168.16.7 s00cbbj down n/a
I promise this is the last questions and then I will go buy a basic shell scripting book. My word of honor!
Last edited by metallica1973; 11-29-2007 at 10:36 AM.
I really apprieciate all of your help. I think this post is too long so I start it in another post. thanks to all for your help. To finish this post with class I will post my grand creation. It still needs work. This script will scan for network devices via IP and or Hostnames and produce a nice file.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.