-   Linux - General (
-   -   nslookup and ping scrips (

dpnctl 02-15-2013 04: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
echo "Server not pingable"

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

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 08:32 AM

Use a loop:

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


function howto() { echo "Bash scripting guides:"; }

*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 11:06 AM.