Home  >  Article  >  System Tutorial  >  Detailed method to solve invalid crontab problem in ubuntu

Detailed method to solve invalid crontab problem in ubuntu

WBOY
WBOYforward
2024-01-01 19:11:541457browse

Enable crontab in Debain's docker. I have been dealing with the problem for a day, so I will record it here. Debain is similar to ubuntu, so it is included under ubuntu.

1. The first question, install crontab

apt-get install cron

Look clearly, it’s cron, not crond! There is no need for things like vixie-cron required for installation under centos! The various tutorials applicable to centos on the Internet really confused me! Remember, only the above command is enough under ubuntu!

2. Start the crontab service

/etc/init.d/cron status  #查看状态

/etc/init.d/cron restart  #启动服务

You can also use ps -ef|grep cron to check the status, or use service start cron to start the service. Just remember one thing, it is cron, not crond! Crond is used by centos.

3. For docker, if you are not using docker, you can skip this step

Modify the /etc/pam.d/cron file, change required to sufficient, and then restart the cron service: /etc/init.d/cron restart

4. The absolute path must be used in the script

Whether it is a shell script or a python script, all paths in it must be absolute paths!

5. Import the required environment variables

example

0 8 * * * . /etc/profile; /bin/sh /home/abc/test.sh

0 8 * * * /bin/usr/python2.7 /home/abc/test.py

If these are all ok, there should be no problem.

The above is the detailed content of Detailed method to solve invalid crontab problem in ubuntu. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:jb51.net. If there is any infringement, please contact admin@php.cn delete