Tuesday, May 7, 2013

Simple tip for cron and at :-)

May be funny but as today's enterprise environment is using more and more automated job schedulers and messaging solutions, cron and at got somewhat sidelined. And all of a sudden I had to schedule a cron job and laugh ha ha - I configured it but just was not seeing the output it took awhile to recollect from the memory - that the output is send by default to the user email.

So if you are testing the cronjob as user rajusa10. run the command mail and check the status of the cron or at job output. That is the default behaviour. You can always modify that redirecting the output via sendmail on SMTP port to the intended recipient.

in the below example:


[rajusa10@rhel-6 ~]$ crontab -l

* * * * * echo "Hi this is a test message"

I am broadcasting the message every minute. Lets test it by command mail





[rajusa10@rhel-6 ~]$ mail
Heirloom Mail version 12.4 7/29/08.  Type ? for help.
"/var/spool/mail/rajusa10": 1 message 1 new
>N  1 Cron Daemon           Tue May  7 13:24  21/770   "Cron echo "Hi this is a test message""

Remove the cron job now or it will keep repeating the message every minute.

Lets test at command : which is used for one time job execution. Once you have entered the command enter and press Ctrl-D that will save the at job for execution depending on the time selected.

[rajusa10@rhel-6 ~]$ at 1:26pm
at> echo "Hello Raj"
at>
job 6 at 2013-05-07 13:26

The output:

Message  3:
From rajusa10@rhel-6.localdomain  Tue May  7 13:26:01 2013
Return-Path:
X-Original-To: rajusa10
Delivered-To: rajusa10@rhel-6.localdomain
Subject: Output from your job        6
To: rajusa10@rhel-6.localdomain
Date: Tue,  7 May 2013 13:26:01 -0700 (PDT)
From: rajusa10@rhel-6.localdomain (Raj)
Status: R

Hello Raj

Some important tips:

1. no need to restart the crond daemon to apply the job updates. cron checks that for every minute by default.
2. No need to mention username while defining with crontab tool





No comments: