$ crontab-e
Example: Execute at two o ' clock every day
0 2 */1 * */usr/bin/python/www/tbktsh/sendms.py &>/dev/null
* * * * * Root run-parts/etc/cron.hourly # every hour to execute scripts within/etc/cron.hourly, "run-parts" This parameter refers to the execution of all files under the folder, do not add this parameter need to give explicit execution script file.
$ Service Crond Restart Or/etc/init.d/crond Restart # restart scheduled task
Note Set executable permissions for script files Oh, otherwise it might not work.
The first column represents the minute (0-59)
The second column represents the Hour (0-23)
The third column represents the day (1-31)
The fourth column represents the month (1-12)
The fifth column represents the week (0-6) 0 for Sunday
"*" represents all numbers within the range of values. "*" is equivalent to "*/1" if used directly
"/" stands for every meaning
"*/5″ means every 5 units
"-" represents a number to a number
"," scattered figures
# Example of Job definition:
#. —————-minute (0–59)
# | . ————-Hour (0–23)
# | | . ———-Day of Month (1–31)
# | | | . ——-month (1–12) OR jan,feb,mar,apr ...
# | | | | .--Day of Week (0–6) (sunday=0 or 7) or Sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * command to be executed
Using CRONTAB-E as root directly is equivalent to editing the/var/spool/cron/root file, which is a user-level scheduled task.
If you set the system level Schedule task, edit the/etc/crontab.
Cron periodically scans all files in the/var/spool/cron/folder every minute (each user will have a timed task file named after the user name) and the/etc/crontab file.
The difference between a user-scheduled task and a system-scheduled task is to send a task message to a different person, and the system schedules the task to be sent to the system administrator, and the user's scheduled task is to send the task message to the current user.
1. Edit directly with crontab command
The Cron service provides the crontab command to set the Cron service, and here are some of the parameters and instructions for this command:
Crontab-u//Set a user's Cron service, which is usually required by the root user when executing this command
CRONTAB-L//list details of a user cron service
Crontab-r//Delete a cron service with no users
CRONTAB-E//Edit a user's cron service
For example, root to view your cron settings: Crontab-u root-l
Again, for example, Root wants to delete Fred's cron settings: Crontab-u fred-r
Schedule Log Related
The/var/log/cron file is the execution record for all scheduled tasks
/var/log/cron.1/var/log/cron.2/var/log/cron.3/var/log/cron.4 These files are archived files
When Crond performs a task failure, it sends a message to the user, and if Crond fails, it can be viewed through the mail log and can be viewed using tail-f/var/spool/mail/root to see the specific error message.
The task in crontab adds its own log, which makes it easier to see why the error output and the standard output are output to MyLog.log after an error.
0 6 * * */www/shservice/task.sh >>/tmp/mylog.log 2>&1
Supplemental knowledge: Anacron can wake up work tasks during shutdown
Linux Cron Scheduled Tasks