LinuxQuestions.org
Visit Jeremy's Blog.
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 06-14-2013, 11:26 AM   #1
selvavinayak88
LQ Newbie
 
Registered: Nov 2012
Location: chennai
Posts: 18

Rep: Reputation: Disabled
how can i run/check my script every time in linux machine


Hi all,

i have a script that checks whether our internet is UP || DOWN. I need to run/check this script every time

set host1=www.google.com
echo $(((ping -w5 -c3 $host1) > /dev/null 2>&1) && echo "up" || (echo "down" && exit 1))


Note: If my internet connection is down machine is automatically send mail...
for this reason I need check/run this code every time

Any body have knowledge please share with me...

Thanks,
Selvavinayakam.na
 
Old 06-14-2013, 11:31 AM   #2
sag47
Senior Member
 
Registered: Sep 2009
Location: Orange County, CA
Distribution: Kubuntu x64, Raspbian, CentOS
Posts: 1,845
Blog Entries: 36

Rep: Reputation: 453Reputation: 453Reputation: 453Reputation: 453Reputation: 453
Quote:
Originally Posted by selvavinayak88 View Post
Hi all,

i have a script that checks whether our internet is UP || DOWN. I need to run/check this script every time

set host1=www.google.com
echo $(((ping -w5 -c3 $host1) > /dev/null 2>&1) && echo "up" || (echo "down" && exit 1))


Note: If my internet connection is down machine is automatically send mail...
for this reason I need check/run this code every time

Any body have knowledge please share with me...

Thanks,
Selvavinayakam.na
Unless you have an alternate internet connection your mail will go undelivered because your internet is down.

That being said assuming you have alternate means of communication for your system, you can run your script regularly using cron (see man pages cron(8), crontab(1), crontab(5)).

I actually recommend you running a more thorough monitoring solution such as Icinga.

SAM
 
Old 06-14-2013, 11:35 AM   #3
karim.ouda
Member
 
Registered: Jun 2013
Posts: 41

Rep: Reputation: 3
so do you want that script should be executed if internet is down or it should be executed continuously.
if you want it should run in regular interval,use crontab and define your time interval so it will run according to that.
 
Old 06-14-2013, 11:57 AM   #4
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 18,504

Rep: Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993
Quote:
Originally Posted by selvavinayak88 View Post
Hi all,
i have a script that checks whether our internet is UP || DOWN. I need to run/check this script every time

set host1=www.google.com
echo $(((ping -w5 -c3 $host1) > /dev/null 2>&1) && echo "up" || (echo "down" && exit 1))


Note: If my internet connection is down machine is automatically send mail...for this reason I need check/run this code every time
Sag47 hit it right on the head...if you don't have a second means of connecting to the Internet, the only way you'll ever get the alert email, is when your Internet connection is WORKING. If you *DO* have a second means of Internet connectivity...your script will STILL fail, since if one connection goes down, your ping command will still work, thereby causing your 'Internet-is-down' check to fail. Unless you have an alternate means of Internet communications, or your script has more than those two lines and is doing alot more processing, what you're trying to do seems like it would never work.
Quote:
Originally Posted by karim.ouda
if you want it should run in regular interval,use crontab and define your time interval so it will run according to that.
Right...sag47 already gave that advice about cron.
 
Old 06-14-2013, 01:12 PM   #5
karim.ouda
Member
 
Registered: Jun 2013
Posts: 41

Rep: Reputation: 3
Quote:
Originally Posted by TB0ne View Post

Right...sag47 already gave that advice about cron.
actually there is only 4 min difference between my post and his post and when i was typing on my device he had posted already that's why i couldnt see his reply.
 
Old 06-14-2013, 01:50 PM   #6
selvavinayak88
LQ Newbie
 
Registered: Nov 2012
Location: chennai
Posts: 18

Original Poster
Rep: Reputation: Disabled
Thanks sam,karim.ouda,TB0ne for suggesting crontab... I am looking on that friends...

after ur's suggestion I created like, for every 5 min email will send to my mail "internet is up". if, i am not getting this mail i take steps to checks internet connection (Alert signal) for every 5Min . is this way is correct ? i am waiting for reply....


Thanks,
Selvavinayakam.na
 
Old 06-14-2013, 01:51 PM   #7
sag47
Senior Member
 
Registered: Sep 2009
Location: Orange County, CA
Distribution: Kubuntu x64, Raspbian, CentOS
Posts: 1,845
Blog Entries: 36

Rep: Reputation: 453Reputation: 453Reputation: 453Reputation: 453Reputation: 453
Quote:
Originally Posted by TB0ne View Post
If you *DO* have a second means of Internet connectivity...your script will STILL fail, since if one connection goes down, your ping command will still work, thereby causing your 'Internet-is-down' check to fail.
I forgot to mention that. Good point. You can add hops to your ping command and force it through a specific gateway if you have an alternate internet connection.

http://superuser.com/questions/31184...ernate-gateway

**EDIT**

Quote:
Originally Posted by selvavinayak88 View Post
after ur's suggestion I created like, for every 5 min email will send to my mail "internet is up". if, i am not getting this mail i take steps to checks internet connection (Alert signal) for every 5Min . is this way is correct ? i am waiting for reply....
That sounds like a really painful heartbeat mechanism. You'll be getting almost 300 emails a day.

If I were you I would have a second server off site (hosting maybe?) which gives an outside perspective of your internet. That outside server can then email you or text message you.

One example would be connecting via public key auth over SSH to a remote server on hosting and outputting a timestamp to a file.

Then you can read that file and if the timestamp is older than 310 seconds then it means the server hasn't checked in in longer than 5 minutes. It would certainly provide a lot less chatter in your email and you would only be notified if it is important.

SAM

Last edited by sag47; 06-14-2013 at 01:58 PM.
 
2 members found this post helpful.
Old 06-14-2013, 01:56 PM   #8
selvavinayak88
LQ Newbie
 
Registered: Nov 2012
Location: chennai
Posts: 18

Original Poster
Rep: Reputation: Disabled
Thanks Sam, I got Right way to explore new things....


Selvavinayakam.na
 
Old 06-14-2013, 02:10 PM   #9
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 18,504

Rep: Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993Reputation: 3993
Quote:
Originally Posted by sag47 View Post
I forgot to mention that. Good point. You can add hops to your ping command and force it through a specific gateway if you have an alternate internet connection.

http://superuser.com/questions/31184...ernate-gateway
**EDIT**
That sounds like a really painful heartbeat mechanism. You'll be getting almost 300 emails a day.

If I were you I would have a second server off site (hosting maybe?) which gives an outside perspective of your internet. That outside server can then email you or text message you.

One example would be connecting via public key auth over SSH to a remote server on hosting and outputting a timestamp to a file.

Then you can read that file and if the timestamp is older than 310 seconds then it means the server hasn't checked in in longer than 5 minutes. It would certainly provide a lot less chatter in your email and you would only be notified if it is important.
+1 for that solution...hadn't even considered that, good call sag47.
 
Old 06-14-2013, 02:30 PM   #10
selvavinayak88
LQ Newbie
 
Registered: Nov 2012
Location: chennai
Posts: 18

Original Poster
Rep: Reputation: Disabled
oK, I accept your point of view...


Selvavinayakam.na


Quote:
Originally Posted by sag47 View Post
I forgot to mention that. Good point. You can add hops to your ping command and force it through a specific gateway if you have an alternate internet connection.

http://superuser.com/questions/31184...ernate-gateway

**EDIT**



That sounds like a really painful heartbeat mechanism. You'll be getting almost 300 emails a day.

If I were you I would have a second server off site (hosting maybe?) which gives an outside perspective of your internet. That outside server can then email you or text message you.

One example would be connecting via public key auth over SSH to a remote server on hosting and outputting a timestamp to a file.

Then you can read that file and if the timestamp is older than 310 seconds then it means the server hasn't checked in in longer than 5 minutes. It would certainly provide a lot less chatter in your email and you would only be notified if it is important.

SAM
 
  


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
Check data and run script ust Linux - Newbie 2 11-02-2012 01:09 PM
How to run a script to a remote linux machine from a windows machine squirrel001 Linux - Newbie 5 05-04-2009 06:06 PM
I want to run script on the server from client machine in windows in a perl script vpradeep Linux - Newbie 2 09-01-2008 03:29 AM
prevent users to run the same script at the same time, on the same machine pvpnguyen Programming 2 09-05-2007 08:52 PM
Is a script, run at boot time from init.d, run with root authority? tmbrwolf53 Linux - Server 2 03-31-2007 08:15 PM


All times are GMT -5. The time now is 12:55 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