Overview
test
Linux system cronjob
- cronjob: hourly, daily, …
|
|
- logrotate calling
1 2 3 4 5 6 7 8 9 10 11 |
[root@xxx cron.daily]# pwd /etc/cron.daily [root@xxx cron.daily]# cat logrotate #!/bin/sh /usr/sbin/logrotate -s /var/lib/logrotate/logrotate.status /etc/logrotate.conf EXITVALUE=$? if [ $EXITVALUE != 0 ]; then /usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]" fi exit 0 |
Logrotate manual
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
NAME logrotate ‐ rotates, compresses, and mails system logs SYNOPSIS logrotate [-dv] [-f|--force] [-s|--state file] config_file .. OPTIONS -d, --debug Turns on debug mode and implies -v. In debug mode, no changes will be made to the logs or to the logrotate state file. -f, --force Tells logrotate to force the rotation, even if it doesn't think this is necessary. -m, --mail <command> -s, --state <statefile> +-v, --verbose Turns on verbose mode. |
Logrotate configuration file
- Sample
shell "/var/log/httpd/access.log" /var/log/httpd/error.log { rotate 5 mail www@my.org size 100k sharedscripts postrotate /usr/bin/killall -HUP httpd endscript }
Knowledge
crontab knowledge
Job format
By default, nnCron uses the enhanced format.
The following graph shows what it consists of:
|
|
Crontab commands
export EDITOR=vi ;to specify a editor to open crontab file.
- crontab -e Edit crontab file, or create one if it doesn’t already exist.
- crontab -l crontab list of cronjobs , display crontab file contents.
- crontab -r Remove your crontab file.
- crontab -v Display the last time you edited your crontab file. (This option is only available on a few systems.)
Examples
tip
(1) * in the value field above means all legal values as in braces for that column.
(2) Repeat pattern like /2 for every 2 minutes or /10 for every 10 minutes
|
|