1

I Want to run Cronjob; after every three hours from last run time for indefinite period and can check whether it ran or not

Could anyone help me in getting what values to be give in this format:

crontab -e

Tried following:

0 0/3 * * * /home/wlogic/SHScripts/DiskCheck/DiskSpaceCheck.sh

When I save file using :wq

I get the message:

crontab: installing new crontab
"/tmp/crontab.vErqAL":1: bad hour
errors in crontab file, can't install.
Do you want to retry the same edit?
4

You should be able to use the following line to run a job every 3 hours:

0 */3 * * * /home/wlogic/SHScripts/DiskCheck/DiskSpaceCheck.sh

To check whether your cron job ran, check your syslog or cron log. This can be different between distributions, for example:

Ubuntu: /var/log/syslog

Dec  1 11:17:01 testhost CRON[6746]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)

CentOS: /var/log/cron

Dec  1 11:01:01 testhost run-parts(/etc/cron.hourly)[13259]: starting 0yum-hourly.cron
Dec  1 11:03:50 server run-parts(/etc/cron.hourly)[13302]: finished 0yum-hourly.cron

Solaris: /var/cron/log

>  CMD: /usr/lib/sa/sa1
>  sys 12394 c Tue Dec  1 11:20:00 2015
<  sys 12394 c Tue Dec  1 11:20:00 2015

If you want to log all output of the scheduled command itself you can use the following:

0 */3 * * * /home/wlogic/SHScripts/DiskCheck/DiskSpaceCheck.sh > /path/to/job-log 2>&1

The above will redirect the output (if any) to the logfile /path/to/job-log and will also redirect the output of STDERR to this logfile.

  • Thanks. This is correct but my question is not answered fully. I mean also asked how to check log whether my script ran or not? – fatherazrael Dec 1 '15 at 10:36
  • What this means -> /path/to/job-log 2>&1 ; i put it like /home/wlogic/SHScripts/DiskCheck/logs/job-log 2>&1 – fatherazrael Dec 1 '15 at 10:51
  • 1
    the > /path/to/job-log part means to redirect STDOUT (standard output) of the command to a file called job-log in directory /path/to (substitute with something like /tmp/DiskSpaceCheck.out). The 2>&1 part means to redirect the output of STDERR (file descriptor 2) to STDOUT (file descriptor 1). – Lambert Dec 1 '15 at 10:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.