Crontab
Open crontab
Use following command to open your user account’s crontab file. Commands in this file run with your user account’s permissions
To open crontab of root account, substitute user
To edit other user crontab
Note : change default editor before running command
Add Task in crontab
Adding New Tasks in that file
You can use an asterisk (*) character to match any value ( run the command /usr/bin/example at 12:30 a.m. every day)
Use comma-separated values to specific multiple times. (runs /usr/bin/example2 at the 15-minute mark on every hour, every day. Make sure you add each new task on a new line.)
Use dash-separated values to specify a range of values (runs /usr/bin/example3 at noon every day, but only in the first six months of the year.)
Shorthands
use shorthands like @yearly, @monthly, @weekly, @daily, @hourly, @reboot (Run once, at startup.)
View
To view crontab entries of current user
To to view crontab entries of the specified user.
Note : (cron prefix file) logs are present in '/var/log/syslog' folder
To check cron is running
Logs
CentOs
Custom
Copy command output to a file for debugging individually
Usage of env variables
- if env variables are used in executing script, then add bin bash line with -l option
Tips
- Have proper permission on bash files to be executed by cron,
- Let bash files have full path cd as first line (else path will be considered from home directory)
- use -l option in bin/bash line if any env variables