LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-12-2013, 01:42 AM   #1
amartlk
Member
 
Registered: Sep 2010
Location: Nagpur India
Posts: 347

Rep: Reputation: 1
script


Hi

i have centos 5.3 installed on server i want to write a script which will check dns ips i.e 214.253.255.231 and 214.253.255.236 is pinging continously if both ips are not pinging then i want to run another .sh file can you pls assist me in same
 
Old 11-12-2013, 01:43 AM   #2
linuxlover.chaitanya
Senior Member
 
Registered: Apr 2008
Location: Nagpur, India
Distribution: Cent OS 5/6, Ubuntu Server 10.04
Posts: 4,629

Rep: Reputation: Disabled
What do you want to achieve from this? Whats the purpose?
 
Old 11-12-2013, 02:05 AM   #3
NM04
Member
 
Registered: Jan 2011
Distribution: Back Track,Fedora,centos
Posts: 239

Rep: Reputation: 14
amartlk,
what exactly do you want to accomplish ?
1) do you want both ip's to be pinged by another one ?
2) OR both ip's should ping each other ?

I would like to help provided you give more details !!

regards,
nm
 
Old 11-12-2013, 02:12 AM   #4
amartlk
Member
 
Registered: Sep 2010
Location: Nagpur India
Posts: 347

Original Poster
Rep: Reputation: 1
Hi

these are the 2 dns ips address of isp i want only ping this 2 ips should ping from my server if both are not pinged the i run one sh file which we restart adsl and my net is working now i do it manually
 
Old 11-12-2013, 02:39 AM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
Please show us what code you've done so far
 
Old 11-12-2013, 02:53 AM   #6
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian Jessie / sid
Posts: 1,471

Rep: Reputation: 444Reputation: 444Reputation: 444Reputation: 444Reputation: 444
Code:
ping -c1 <ip> || FixTheInternet.sh
expanded
Code:
ping -c1 <ip> || dns1=1 && dns1=0
ping -c1 <ip2>|| dns2=1 && dns2=0
(( "$dns1" == "0" && "$dns2" == "0" )) || FixTheInterWebs.sh
 
Old 11-12-2013, 03:56 AM   #7
amartlk
Member
 
Registered: Sep 2010
Location: Nagpur India
Posts: 347

Original Poster
Rep: Reputation: 1
Thanks for reply
it is ok as below where below are 2 ip of dns
ping -c1 <214.253.255.231> || dns1=1 && dns1=0
ping -c1 <214.253.255.236>|| dns2=1 && dns2=0
(( "$dns1" == "0" && "$dns2" == "0" )) || FixTheInterWebs.sh
 
Old 11-12-2013, 04:12 AM   #8
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian Jessie / sid
Posts: 1,471

Rep: Reputation: 444Reputation: 444Reputation: 444Reputation: 444Reputation: 444
no, remove < and >

<ip> and <ip2> were intended as 'markers'

Code:
ping -c1 214.253.255.231 || dns1=1 && dns1=0
ping -c1 214.253.255.236 || dns2=1 && dns2=0
(( "$dns1" == "0" && "$dns2" == "0" )) || FixTheInterWebs.sh
you will still need to do some work for that to do what you want

while I'm at it,
a re-write
Code:
for ip in 214.253.255.231 214.253.255.236;do
    ping -c1 $ip || ( FixTheInterWebs.sh; break )
done
does the same, but less 'messing about'

Last edited by Firerat; 11-12-2013 at 04:15 AM.
 
Old 11-12-2013, 04:35 AM   #9
amartlk
Member
 
Registered: Sep 2010
Location: Nagpur India
Posts: 347

Original Poster
Rep: Reputation: 1
#!/bin/bash

for ip in 214.253.255.231 214.253.255.236;
do
ping -c1 $ip || ( FixTheInterWebs.sh; break )
done


is this correct now
 
Old 11-12-2013, 05:09 AM   #10
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
@amartlk: Have you tried running Firerat's examples?

The only way to learn anything is to try to understand what's going on and play around with the given examples.

If there's something specific about the code you don't understand we can/will explain it to you.
 
Old 11-12-2013, 05:14 AM   #11
amartlk
Member
 
Registered: Sep 2010
Location: Nagpur India
Posts: 347

Original Poster
Rep: Reputation: 1
Hi

ya i want to understand the flow of code thats why i ask you
 
Old 11-12-2013, 05:30 AM   #12
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
Quote:
Originally Posted by amartlk View Post
ya i want to understand the flow of code thats why i ask you
Which example and what part are you unclear about?
 
Old 11-12-2013, 05:33 AM   #13
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian Jessie / sid
Posts: 1,471

Rep: Reputation: 444Reputation: 444Reputation: 444Reputation: 444Reputation: 444
Quote:
Originally Posted by amartlk View Post
#!/bin/bash

for ip in 214.253.255.231 214.253.255.236;
do
ping -c1 $ip || ( FixTheInterWebs.sh; break )
done


is this correct now
well, the script is ok,, but my logic is broken

the examples I have given are not difficult

lets ignore the second one for now, and look at what the first is doing

Code:
ping -c1 214.253.255.231 || dns1=1 && dns1=0
# if ping ( with count of 1 , so only one ping ) 214.253.255.231 returns a none-zero  exit (error ) set variable  dns1 to 1
# if exit is 0 ( no error ) set variable  dns1 to 0
# repeat with second ip , var is dns2
(( "$dns1" == "0" && "$dns2" == "0" )) || FixTheInterWebs.sh
# if var dns1 AND dns2 are both 0 return 'true'
# if either dns1 or dns2 are not zero return 'false'
# || ( action if false )
alternative
Code:
ping -c1 214.253.255.231;dns1=$?
ping -c1 214.253.255.236;dns2=$?
if (( "$dns1" != "0" && "$dns2" != "0" )); then
    FixTheInterWebs.sh
fi

there is not much else I can type about this
there are a number of ways to do it



anyway, back to my broken logic
Code:
for ip in 214.253.255.231 214.253.255.236;
do
    ping -c1 $ip || ( FixTheInterWebs.sh; break )
done
this is broken as it will run FixTheInterWebs.sh if 214.253.255.231 is 'down' even if 214.253.255.236 'up'
you want to Fix the Interwebs if both dns servers are 'down'
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell script/Perl Script to remove the string until it finds special character '_' pooppp Programming 10 07-17-2012 10:36 AM
Shell script/Perl Script to remove the string until it finds special character '_' pooppp Programming 1 07-13-2012 02:03 AM
[SOLVED] bash and xterm: how make apps started by and for a script persist when script terminates porphyry5 Linux - General 4 06-15-2011 02:27 PM
[SOLVED] Script question: create a shell script in kde to log in on a server with ssh c4719929 Linux - Newbie 1 01-31-2011 04:05 AM
How to get full path to script file inside script itself? And in case of sym links? maggus Linux - Newbie 3 05-28-2009 09:40 AM


All times are GMT -5. The time now is 06:38 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration