The scene on pit

Crontab sets a scheduled task, but the task is not executed when the time is up

Avoid pit guide

1. Check whether the crontab task is executed

To confirm that the task is executed, view the crontab execution log directory:/var/log/cron Confirming that the task is executed determines that the execution process of the task failed

2. Common causes of task execution failure

1. The execution file has no execution permission

00 10 * * 6 /mnt/root/test.sh

You need to add the execute permission chmod 777 / MNT /root/test.sh to the execute file

2. No absolute path is specified in the internal command

eg

#! /bin/bash
cd /mnt/root
python3 test.py
Copy the code

Python3 for this script needs to be changed to an absolute path, as shown below

#! /bin/bash
cd /mnt/root
/mnt/anaconda3/envs/py36/bin/python3 test.py
Copy the code

3. The printed content contains Chinese characters. The console does not support the display of Chinese characters

#! /bin/bashExport LANG = "en_US. UTF- 8 -">> ~/.bash_profile source ~/.bash_profilecd /mnt/root
/mnt/anaconda3/envs/py36/bin/python3 test.py
Copy the code

4. For more execution errors, you can directly output the execution log file in the specified directory to view the cause

47 13 * * * /mnt/root/test.sh > /mnt/root/output.log 2> &1
Copy the code