A crontab file contains instructions to the cron daemon of the general form: "runthis command at this time on this date". Each user has their own crontab, and commands in any given crontab will be executed as the user who owns the crontab.
Blank lines and leading spaces and tabs are ignored. Lines whose first non-spacecharacter is a pound-sign (#) are comments, and are ignored. Note that comments are not allowed on the same line as cron commands, since they will be taken to bepart of the command. Similarly, comments are not allowed on the same line as environment variable settings.
How to view existing crontab: crontab -l
[root@localhost~]# crontab -l
1 * * * * /usr/sbin/logrotate -s /home/ajay/logdumps/script/logrotate.state /home/ajay/logdumps/script/logrotate.conf
0 5 * * * >/tmp/App.log
How to edit or create crontab : crontab -e
It will open a editable screen and save as :wq (vim editor command). It will automatically install new/modified one.
[root@localhost~]# crontab -e
crontab:installing new crontab
These special time specification "nicknames" are supported, which replace the 5 initial time and date fields, and are prefixed by the '@ character:
@reboot : Run once after reboot.
@yearly : Run once a year, ie. "0 0 1 1 *".
@annually : Run once a year, ie. "0 0 1 1 *".
@monthly : Run once a month, ie. "0 0 1 * *".
@weekly : Run once a week, ie. "0 0 * * 0".
@daily : Run once a day, ie. "0 0 * * *".
@hourly : Run once an hour, ie. "0 * * * *".
Crontab format :
minutes(0-59) hours(0-23) date(1-31) month(1-12) weekdays(0-6) command
* denotethat all possible values.
Each filed can be multiple with comma separated. e.g.
I want to clear logfile twice a day so my crontab will be
[root@localhost~]# crontab -l
0 8,20 * * * >/tmp/App.log
Explanation:
0 : 0th minute (top of hour)
8,20 : 8'o clock in morning and 8'o clock in evening
* : everyday
* : every month
* : each day of week
lets if we want to do this exercise during weekdays only
[root@localhost~]# crontab -l
0 8,20 * * 1-5 >/tmp/App.log
so i have modified my weekdays value to 1-5 (Monday-Friday).
Blank lines and leading spaces and tabs are ignored. Lines whose first non-spacecharacter is a pound-sign (#) are comments, and are ignored. Note that comments are not allowed on the same line as cron commands, since they will be taken to bepart of the command. Similarly, comments are not allowed on the same line as environment variable settings.
How to view existing crontab: crontab -l
[root@localhost~]# crontab -l
1 * * * * /usr/sbin/logrotate -s /home/ajay/logdumps/script/logrotate.state /home/ajay/logdumps/script/logrotate.conf
0 5 * * * >/tmp/App.log
How to edit or create crontab : crontab -e
It will open a editable screen and save as :wq (vim editor command). It will automatically install new/modified one.
[root@localhost~]# crontab -e
crontab:installing new crontab
These special time specification "nicknames" are supported, which replace the 5 initial time and date fields, and are prefixed by the '@ character:
@reboot : Run once after reboot.
@yearly : Run once a year, ie. "0 0 1 1 *".
@annually : Run once a year, ie. "0 0 1 1 *".
@monthly : Run once a month, ie. "0 0 1 * *".
@weekly : Run once a week, ie. "0 0 * * 0".
@daily : Run once a day, ie. "0 0 * * *".
@hourly : Run once an hour, ie. "0 * * * *".
Crontab format :
minutes(0-59) hours(0-23) date(1-31) month(1-12) weekdays(0-6) command
* denotethat all possible values.
Each filed can be multiple with comma separated. e.g.
I want to clear logfile twice a day so my crontab will be
[root@localhost~]# crontab -l
0 8,20 * * * >/tmp/App.log
Explanation:
0 : 0th minute (top of hour)
8,20 : 8'o clock in morning and 8'o clock in evening
* : everyday
* : every month
* : each day of week
lets if we want to do this exercise during weekdays only
[root@localhost~]# crontab -l
0 8,20 * * 1-5 >/tmp/App.log
so i have modified my weekdays value to 1-5 (Monday-Friday).
No comments:
Post a Comment