Linux crontab micromanipulation

First introduce two commonly used commands.

  1. crontab -e edits timed tasks. For time setting, please refer to the online generation tool
  2. crontab -l lists the timed tasks under the current user.
    Note : The emphasis here is on the current user , because the timed task recognizes the user, so you must first specify the user when setting the timed task.

Secondly, pay attention to the path. Usually, the required operations are encapsulated in a shell script before using crontab. The operation of the file in the script needs to use an absolute path. For example, if you plan to empty the /app/test/a.txt file, put the script under /app/shell, and name it clr_content.sh, the following is the wrong and correct writing:
wrong writing :

#clear the a.txt content
echo "" > ../test/a.txt

Running alone can be executed successfully, but adding to the crontab list will not be able to execute.

Correct writing

#clear the a.txt content
echo "" > /app/test/a.txt

Finally, you need to pay attention to the Linux system time and time zone settings, if it is Beijing time, it doesn't matter. if not:

  1. Adjust to Beijing time (recommended)
  2. Calculate the time difference when setting timed tasks

Guess you like

Origin blog.csdn.net/hongyinanhai00/article/details/108307726