Crontab and its logs

Frist time I am writing crontab.

Following is structure of time and Date

# * * * * * command to execute # │ │ │ │ │ # │ │ │ │ │ # │ │ │ │ └───── day of week (0 - 6) (0 to 6 are Sunday to Saturday, or use names; 7 is Sunday, the same as 0) # │ │ │ └────────── month (1 - 12) # │ │ └─────────────── day of month (1 - 31) # │ └──────────────────── hour (0 - 23) # └───────────────────────── min (0 - 59)

I put entry like following

00 06 * /bin/sh /opt/cleanup.sh

Think this is not woring.

Where can I see any log of crontab??

-------------Problems Reply------------

Usually the cron commands' output is sent to the owner via mail (man mail), but this when you execute a code that returns an output (stdout and stderr). When you login you should see something like "There are new mails". I don't know though if wrong cron schedules like yours (see @fedorqui's reply) throw an error log. In any case to have the output and error of the scheduled cron jobs on file instead of on mail, you can redirect the output like this:

00 06 * * * /bin/sh /opt/cleanup.sh > /where/you/have/write/permission/cleanup.log 2>&1

If you want to append rather than overwrite, just use two >, like this:

00 06 * * * /bin/sh /opt/cleanup.sh >> /where/you/have/write/permission/cleanup.log 2>&1

To disable the log, simply schedule the following:

00 06 * * * /bin/sh /opt/cleanup.sh > /dev/null 2>&1

2>&1 means "redirect the channel 2 (error) to the pointer of channel 1 (standard output)". The standard output is redirected to the file (/my/file.sh > /my/file.log).

You need to use all the parameters. So to run every day at 6am use:

00 06 * * * /bin/sh /opt/cleanup.sh

You can see the logs in /var/log/cron, probably.

For further information, you can check the beautifully written section Debugging crontab in [crontab] tag wiki.

Category:crontab Views:0 Time:2018-10-09

Related post

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.167 (s). 11 q(s)