Linux crontab Command Detailed

Source: Internet
Author: User

Crontab: The daemon of timed tasks, accurate to minute, design the second we generally write the script--equivalent to the alarm clock
Log file: ll/var/log/cron*
Edit file: Vim/etc/crontab
Process: Ps-ef | grep crond ==>/etc/init.d/crond Restart
Role: Scheduled backup, real-time backup

Common Command Parameters

Common Command Display


Crontab Usage Summary


                          Best use 2 for Arabic numerals display
                         Weeks and days are best not to use
                         timed tasks to add annotations
                         can be directed to a log file or to an empty file
                          the scheduled task must be an absolute path, and the directory has to exist to produce results
                         crontab Service Be sure to turn on run

Production Commissioning Scheduled Tasks


1. Increase the frequency of task execution
2. Adjust system time commissioning tasks, 5 minutes in advance and not for production environments
3. Debug timed tasks with script log output
4. Note the problem with some task commands--Ensure that the command is correct

Crontab Proverbs

1. Environmental variables issues, such as crontab environment variables that do not recognize Java
When Crontab executes the shell, only a few environment variables are recognized, and normal environment variables are unrecognized, so when writing the shell it is best to use export to re-declare the variables to ensure that the script executes.
2. The execution of the command is best scripted
3. Script Permissions plus/bin/sh, canonical path/server/scripts
4. Time variables are escaped with a backslash, preferably with a script
5. Add comments to a timed task
6.>/dev/null 2>&1 ==>&>/dev/null, don't feel free to print log files
7. The program script inside the scheduled task uses the full path as far as possible
8. Avoid unnecessary programs and command output
9. Add comments before Scheduled tasks
10. Package to the top level of the file directory

CRONTAB specification


Timed tasks to add necessary comments (who, what time, who, what things)
Timed tasks or programs are best written in scripts----Script execution
Date +%f\%h:%m:%s--write crontab-e need to escape%, otherwise error
Cd/etc && tar czf/root/service_$ (date +\%f\ \%h:\%m:\%s). tar.gz./services
Execute shell script, preferably/bin/sh (can be executed with or without permissions)
End of scheduled task plus/dev/null 2>$1 (==> &>/dev/null ==> 1>/dev/null 2>/dev/null)

-timed tasks, once per execution, send a message to the administrator (/var/spool/clientsqueuq---------directly deleted, with LS | xargs rm), the temporary path of the message will be invalid to occupy the Inode
Perform related tasks under the specified user
Production task program do not print output information arbitrarily
Script to perform timed tasks to canonical path (absolute path)
In case of packaging
1. To the parent directory packaging/etc/services to/root
2. If the sub-level package, the time should be accurate to the points
Cd/etc
Tar czf/root/service_$ (date +%f\%h:%m:%s). tar.gz./services
Configure timed task specification operation procedures to prevent errors
After the command test succeeds, copy to the script
After the test script succeeds, copy the canonical path of the script to Crotab-e

Linux crontab Command Detailed

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.