Tag the AWS EBS volume with disk drive letter or label
March 26, 2018
How to test if the user is present in Active Directory via PowerShell
March 26, 2018

How to add task in cron

Each user has their own cron file including the root user. If the cron task requires administrative privilege then it can be added to the root cron task file. For more details on cron tasks, the can run the commands man crontab

Edit your own cron task (The current user)

crontab -e

You can switch to the root user and run the above command on Ubuntu/Debian we can use the sudo command to edit the root user’s cron task

sudo crontab -e

CRONTAB OPTIONS

#list crontab(printed to the output/screen)

crontab -l

#edit crontab

crontab -e

#remove crontab

crontab -r

Crontab Format

minute (0-59), hour (0-23, 0 = midnight), day (1-31), month (1-12), weekday (0-6, 0 = Sunday), command

minute hour day month weekday command

EVERY DAY AT A SPECIFIC TIME

every day at 5:21 am

21 05 * * * /usr/bin/somedirectory/somecommand

every day at 5:21 pm

21 17 * * * /usr/bin/somedirectory/somecommand

RUN EVERY X AMOUNT OF TIME (ex. every 10 minutes)

Run at every minute interval pass the hour

*/10 * * * * /usr/bin/somedirectory/somecommand

EVERY DEFINED MINUTE

Every hour on the dot and at 10,20,30,40,50 past the hour

0,10,20,30,40,50 * * * * /usr/bin/somedirectory/somecommand

EXAMPLE OF ALL THE FIELDS TOGETHER

The above example will run /usr/bin/somedirectory/somecommand at 01 and 31 past the hours(note the comma. 0,31) in the 4:00 am and 5:00 am an hour on the 1st through the 15th of every January and June(note the comma again).

01,31 04,05 1-15 1,6 * /usr/bin/somedirectory/somecommand

RESTRICT CRONTAB ACCESS

If the /etc/cron.allow file exists, then users must be listed in it in order to be allowed to run the crontab command. If the /etc/cron.allow file does not exist but the /etc/cron.deny file does, then users must not be listed in the /etc/cron.denyfile in order to run crontab. In the case where neither file exists, the default on current Ubuntu (and Debian, but not some other Linux and UNIX systems) is to allow all users to run jobs with crontab. For more information crontab see: https://help.ubuntu.com/community/CronHowto

Comments are closed.

Bitnami