LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   nslookup and ping scrips (http://www.linuxquestions.org/questions/linux-general-1/nslookup-and-ping-scrips-4175450235/)

dpnctl 02-15-2013 03:27 AM

nslookup and ping scrips
 
I defined a script to report if ping & nslookup are not working, which looks like this:

************
function server_precheck_function
{
ping $server > /dev/null
if [ $? -eq 0 ]; then
exit
else
echo "Server not pingable"
fi

host $server > /dev/null
if [ $? -eq 0 ]; then
exit
else
echo "Server not Resolved"
fi
}


server1=$(command to find server1)
server2=$(command to find server2)
server3=$(command to find server3)

************

I would like to call the functions server_ping_check & server_lookup_check for all 3 servers in the same script, something like this

server_ping_check_function server1
server_ping_check_function server2
server_ping_check_function server3

as of now I am running the functions as individual scripts within the same script, how do I call like explained above, pls see if any one can assist.

unSpawn 02-15-2013 07:32 AM

Use a loop:
Code:

command to find server1 server2 server3 | while read SERVER; do
 server_ping_check_function "${SERVER}"
done

Code:

function howto() { echo "Bash scripting guides:
http://www.tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html
http://www.tldp.org/LDP/Bash-Beginners-Guide/html/index.html
http://www.gnu.org/software/bash/manual/html_node/index.html
http://www.grymoire.com/Unix/Sh.html
http://www.tldp.org/LDP/abs/html/
http://mywiki.wooledge.org/BashFAQ
http://mywiki.wooledge.org/BashPitfalls"; }


*BTW also have a look at command args (esp. how many times you query, query timeouts and quiet output), realize that not being able to ping a server can have different causes (it doesn't necessarily mean a server is down) and that name lookups can be cached by subsystems like nscd or a caching name server.


All times are GMT -5. The time now is 08:12 AM.