linux cron task --crontab

There is a lot of information on the Internet, only an excerpt:


the best typesetting: http://www.cnblogs.com/chen-lhx/p/5996781.html

crontab will check every minute whether there is a command in the crontab file corresponding to the current user that matches the timing condition, if any, execute the command.

  • Edit the crontab file: crontab -e
  • List all cron tasks of the current user: crontab -l
  • Delete all cron tasks: crontab -r

A line in the crontab file has the following format:
minute hour day month week /home/xx/command.sh

quote
  • Asterisk (*): represents all possible values. For example, if the month field is an asterisk, it means that the command operation will be executed every month after the constraints of other fields are met.
  • Comma (,): A list range can be specified with comma-separated values, for example, "1,2,5,7,8,9"
  • Middle bar (-): You can use a middle bar between integers to represent a range of integers, for example "2-6" means "2,3,4,5,6"
  • Forward slash (/): You can specify the interval frequency of time with a forward slash, for example "0-23/2" means to execute every two hours. At the same time, forward slashes can be used together with asterisks, such as */10, if used in the minute field, it means to execute every ten minutes.


Notice:
  • It is recommended to add >/dev/null 2>&1 & to the command in the .sh file to redirect the output and run it in the background
  • Paths in .sh files must use absolute paths
  • Environment variables may be missing from the .sh file and must be added by yourself, for example: source /etc/profile; command


Running log: tail /var/log/cron

Specific reference:


Deployment (running through crontab)
The environment set through pyenv local xx is invalid when running through crontab.
To make the configuration take effect, the method is very simple:
modify the environment variable PATH before executing the command (I did another step: cd to the root of my code)
export PATH=~/.pyenv/shims:~/.pyenv/bin:"$PATH"

This way, the python in ~/.pyenv/shims will be retrieved before the system default python.

See : https://github.com/pyenv/pyenv/wiki/Deploying-with-pyenv

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326178691&siteId=291194637