1. crontab-E: edit the scheduled task. View crontab-L. The final cron task file is saved in the/var/spool/cron/crontab directory.
2. cron switches to the owner of the cron file in the/var/spool/cron/crontab directory and then runs the defined scheduled task.
3. When a Cron user is switched, no environment variables, including. bashrc, will be executed. Therefore, variables such as $ home are not defined. Therefore, in the script of the scheduled task, we will handle it like this:
#! /Bin/bash
Home =/home/markz
Source $ {home}/. bashrc
Export Path =/usr/local/bin: $ path
And then the specific task to be executed.
Note that ,~ /. Bashrc usually contains a lot of definitions and script execution, which may affect the successful execution of source. The reason why we add this source to the script that requires cron is to define some environment variables in most cases. So in order to ensure the success of source, we generally store the required environment variables in a file separately, and then go to the source file. Direct source ~ /. Bashrc is not a good practice.
4./var/log/syslog stores the cron log. You can view the log to conveniently know the execution status of the scheduled task.