LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 02-15-2013, 03:27 AM   #1
dpnctl
LQ Newbie
 
Registered: Mar 2010
Posts: 15

Rep: Reputation: 0
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.
 
Old 02-15-2013, 07:32 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
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.
 
  


Reply

Tags
bash, function, scripting



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
can't update scientific linux, and ping, nslookup not working as well bobba.surendra Linux - Newbie 1 12-29-2012 03:38 PM
[SOLVED] ping is working but not nslookup call_krushna Linux - Server 1 07-29-2012 08:13 AM
ping does not resolve name while nslookup does jmonatsys0 Linux - Networking 6 09-07-2010 03:00 PM
[SOLVED] ping / nslookup / host not working j66788 Linux - Networking 5 10-07-2009 05:52 PM
nslookup works, ping doesn't coolnicklas Linux - Networking 5 04-16-2005 08:23 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:12 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration