In Linux, you can run scripts on a regular basis by writing them in scripts (such as SH), as needed, and then by Crontab.
The task scheduling under Linux is divided into two categories, system task scheduling and user task scheduling.
System task scheduling: The work to be performed by the system periodically, such as writing cache data to hard disk, log cleanup, etc. In the/etc directory there is a crontab file, this is the System Task Scheduler configuration file.
User Task scheduling: Users to perform regular work, such as user data backup, scheduled email reminders and so on. Users can use the Crontab tool to customize their own scheduled tasks. All user-defined crontab files are saved in the/var/spool/cron directory. Its file name is the same as the user name.
User Permissions File:
Files:/etc/cron.deny
Description: The user listed in this file is not allowed to use the crontab command
Files:/etc/cron.allow
Description: Users listed in this file are allowed to use the crontab command
Files:/var/spool/cron/
Description: Directory of all user crontab files, named after user name
How to use:
(1) Create a new crontab file
Create a file to write a timed run statement in the file, as shown below
* * * * * */root/newtest. SH
WHERE * * * * * represents the time of day and month, the 5 asterisks represent a newtest.sh script that runs once every minute.
(2) Submit and run the crontab file
Crontab Mycron
Mycron The crontab file name that you created for you.
Other commands for Crontab
(1) Edit crontab file
If you want to add, delete, or edit an entry in the Crontab file, and the E D I to r environment variable is set to V I, then you can edit the crontab file with V I, and the corresponding command is:
$ crontab-e
(2) Delete crontab file
To delete a crontab file, you can use:
$ crontab-r
(3) Recover lost crontab files
If you accidentally delete the crontab file, assuming you have a backup in your own $ H O M directory, you can copy it to/var/spool/cron/<username>, where <username> is the user name. If the copy cannot be completed due to a permissions issue, you can use:
$ crontab <filename>
Where,<filename> is the file name of your copy in the $ H O M e directory.
I recommend that you save a copy of the file in your own $ H O M directory. I have had a similar experience, several times accidentally deleted the crontab file (because the R key is close to the E key to the right). This is why some system documentation does not recommend editing the crontab file directly, but instead edits a copy of the file and then resubmit the new file.
Some variants of crontab are somewhat bizarre, so be careful when using the crontab command. If you omit any of the options, crontab may open an empty file, or it might look like an empty file. Then hit the delete key to exit, do not press <ctrl-d>, otherwise you will lose the crontab file.
(4) To view the implementation of Crontab
$ tail-f/var/log/cron
Crontab (Linux scheduled execution of task commands)