LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   crontab example (https://www.linuxquestions.org/questions/linux-newbie-8/crontab-example-4175599628/)

hack3rcon 02-13-2017 02:08 AM

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.

astrogeek 02-13-2017 02:11 AM

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.

Turbocapitalist 02-13-2017 04:08 AM

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)


r3sistance 02-13-2017 05:19 AM

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.

JJJCR 02-15-2017 03:49 AM

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!

hack3rcon 02-18-2017 05:40 AM

Quote:

Originally Posted by r3sistance (Post 5669725)
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.

hack3rcon 02-18-2017 05:40 AM

Quote:

Originally Posted by Turbocapitalist (Post 5669706)
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?

Turbocapitalist 02-18-2017 11:40 AM

Quote:

Originally Posted by hack3rcon (Post 5672522)
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.


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