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 would need your help to get this script some modification, this script will print
the live hosts, i need only to count the word "up" then i will know how many hosts are up on the network:
Code:
#!/bin/bash
is_alive_ping()
{
ping -c 1 $1 > /dev/null
[ $? -eq 0 ] && echo Node with IP: $i is up.
}
for i in 192.168.0.{1..254}
do
is_alive_ping $i & disown
done
Thanks teckk and Habitual for your respond, what i need is just to add "count" option so the output will show only the numeric of "up" hosts like 60 or 10 base on
counting "up" keyword and print only the number.
what i need, is only to count the number of "up" hosts, the scrip that i post output:
Node with IP: 192.168.0.3 is up.
Node with IP: 192.168.0.1 is up.
Node with IP: 192.168.0.12 is up.
Node with IP: 192.168.0.10 is up.
Node with IP: 192.168.0.15 is up.
Node with IP: 192.168.0.20 is up.
Node with IP: 192.168.0.45 is up.
Node with IP: 192.168.0.90 is up.
Node with IP: 192.168.0.60 is up.
Node with IP: 192.168.0.16 is up.
Node with IP: 192.168.0.11 is up.
Node with IP: 192.168.0.18 is up.
Node with IP: 192.168.0.21 is up.
Node with IP: 192.168.0.4 is up.
i need the script to count the "up" keyword and give me the output as only:
14
even no need for the full output like "Node with IP: 192.168.0.4 is up" main purpose is to count up hosts at a given time of running the script.i need to run the script multiple time against subnet for troubleshooting purpose not monitoring or administration.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.