LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 02-13-2017, 03:08 AM   #1
hack3rcon
Senior Member
 
Registered: Jan 2015
Posts: 1,432

Rep: Reputation: 10
Post crontab example


Hello.
I run "crontab -e" and add below task:
* * * * * /bin/ping google.com
and it mean that my system must ping google every day and every time but I can't see the result!!!
How can I see it?

Thank you.
 
Old 02-13-2017, 03:11 AM   #2
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_12{.0|.1}
Posts: 5,352
Blog Entries: 11

Rep: Reputation: 3319Reputation: 3319Reputation: 3319Reputation: 3319Reputation: 3319Reputation: 3319Reputation: 3319Reputation: 3319Reputation: 3319Reputation: 3319Reputation: 3319
Where would you expect to see it?

Cron is not connected to a terminal. You can send it to a file or have cron email it to you.

And if you must ping from cron, you really should limit how long that process continues.

Last edited by astrogeek; 02-13-2017 at 03:17 AM. Reason: additional comments
 
1 members found this post helpful.
Old 02-13-2017, 05:08 AM   #3
Turbocapitalist
Senior Member
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 4,470
Blog Entries: 3

Rep: Reputation: 2232Reputation: 2232Reputation: 2232Reputation: 2232Reputation: 2232Reputation: 2232Reputation: 2232Reputation: 2232Reputation: 2232Reputation: 2232Reputation: 2232
IIRC the default is that output is sent as a local e-mail. Check your local mailbox.

You might even be able to trick it into showing a graphical dialog by setting the DISPLAY variable, assuming it is the same account that you are running the desktop environment on:

Code:
# untested
00 * * * * DISPLAY=:0.0 /usr/bin/xmessage -buttons 'OK' $(/bin/ping -c 3 -w 1 google.com)
 
Old 02-13-2017, 06:19 AM   #4
r3sistance
Senior Member
 
Registered: Mar 2004
Location: UK
Distribution: CentOS 6/7
Posts: 1,375

Rep: Reputation: 217Reputation: 217Reputation: 217
You could use simple output redirection

* * * * * /bin/ping google.com >> /path/to/file

Altho if I were to do it, I'd create a bash script so that you can get the time/date in that resulting file too.

Also you say that it must ping google everyday, this is incorrect, you've set this up to run every minute. You would need to set an explicit time to make it daily, such as

15 2 * * * /bin/ping google.com >> /path/to/file

This would make it run at 2:15AM everyday.
 
1 members found this post helpful.
Old 02-15-2017, 04:49 AM   #5
JJJCR
Senior Member
 
Registered: Apr 2010
Posts: 1,645

Rep: Reputation: 278Reputation: 278Reputation: 278
As "astrogeek" had mentioned, you should limit the ping.

In Windows if you ping blahblah.com it will ping 4 times.

But in Linux you need to specify the option "-c" as others has already mentioned.

Adjust the ping to:

/bin/ping -c 4 -w 1 google.com

It will ping 4 times and not infinite.

Good luck!
 
Old 02-18-2017, 06:40 AM   #6
hack3rcon
Senior Member
 
Registered: Jan 2015
Posts: 1,432

Original Poster
Rep: Reputation: 10
Quote:
Originally Posted by r3sistance View Post
You could use simple output redirection

* * * * * /bin/ping google.com >> /path/to/file

Altho if I were to do it, I'd create a bash script so that you can get the time/date in that resulting file too.

Also you say that it must ping google everyday, this is incorrect, you've set this up to run every minute. You would need to set an explicit time to make it daily, such as

15 2 * * * /bin/ping google.com >> /path/to/file

This would make it run at 2:15AM everyday.

Thank you a lot.
 
Old 02-18-2017, 06:40 AM   #7
hack3rcon
Senior Member
 
Registered: Jan 2015
Posts: 1,432

Original Poster
Rep: Reputation: 10
Quote:
Originally Posted by Turbocapitalist View Post
IIRC the default is that output is sent as a local e-mail. Check your local mailbox.

You might even be able to trick it into showing a graphical dialog by setting the DISPLAY variable, assuming it is the same account that you are running the desktop environment on:

Code:
# untested
00 * * * * DISPLAY=:0.0 /usr/bin/xmessage -buttons 'OK' $(/bin/ping -c 3 -w 1 google.com)
local mailbox?
 
Old 02-18-2017, 12:40 PM   #8
Turbocapitalist
Senior Member
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 4,470
Blog Entries: 3

Rep: Reputation: 2232Reputation: 2232Reputation: 2232Reputation: 2232Reputation: 2232Reputation: 2232Reputation: 2232Reputation: 2232Reputation: 2232Reputation: 2232Reputation: 2232
Quote:
Originally Posted by hack3rcon View Post
local mailbox?
Depending on your distro and setup you may have a mail server running but set to only deal with mail internal to the machine itself. The normal way for cron to communicate with people is to send e-mails containing the output from any cron jobs if there was any output.
 
  


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
automatic crontab backup of crontab brcjacks Linux - General 4 10-19-2015 04:21 AM
[SOLVED] crontab does not reread the crontab file upon modification of the latter. stf92 Slackware 4 08-01-2015 07:12 PM
[SOLVED] Problem with crontab:: command not executed properly via crontab Ankush Seth Linux - Newbie 11 11-11-2013 07:25 AM
DIff B/w Crontab -l & crontab -e Tareq9959 Linux - Newbie 2 05-14-2013 09:27 AM
system-wide crontab in /etc/crontab ner Linux - General 2 11-18-2003 01:35 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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