LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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, 02:08 AM   #1
hack3rcon
Senior Member
 
Registered: Jan 2015
Posts: 1,432

Rep: Reputation: 11
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, 02:11 AM   #2
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,269
Blog Entries: 24

Rep: Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196Reputation: 4196
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 02:17 AM. Reason: additional comments
 
1 members found this post helpful.
Old 02-13-2017, 04:08 AM   #3
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,333
Blog Entries: 3

Rep: Reputation: 3729Reputation: 3729Reputation: 3729Reputation: 3729Reputation: 3729Reputation: 3729Reputation: 3729Reputation: 3729Reputation: 3729Reputation: 3729Reputation: 3729
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, 05: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, 03:49 AM   #5
JJJCR
Senior Member
 
Registered: Apr 2010
Posts: 2,161

Rep: Reputation: 449Reputation: 449Reputation: 449Reputation: 449Reputation: 449
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, 05:40 AM   #6
hack3rcon
Senior Member
 
Registered: Jan 2015
Posts: 1,432

Original Poster
Rep: Reputation: 11
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, 05:40 AM   #7
hack3rcon
Senior Member
 
Registered: Jan 2015
Posts: 1,432

Original Poster
Rep: Reputation: 11
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, 11:40 AM   #8
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,333
Blog Entries: 3

Rep: Reputation: 3729Reputation: 3729Reputation: 3729Reputation: 3729Reputation: 3729Reputation: 3729Reputation: 3729Reputation: 3729Reputation: 3729Reputation: 3729Reputation: 3729
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



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

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

All times are GMT -5. The time now is 12: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
Open Source Consulting | Domain Registration