Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to execute python tasks regularly in linux system

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

In this issue, the editor will bring you about how to regularly execute python tasks in the linux system. The article is rich in content and analyzes and describes for you from a professional point of view. I hope you can get something after reading this article.

Crontab-l view scheduled tasks:

# capture price information regularly at 06:10 every morning, and capture pigs and cattle 10 6 * / opt/sh/pork_worm.sh#50 11 * python3 / opt/price_worms/pork_worm_daily.py

Where pork_worm.sh runs the python instruction for only one shell script. (those who want the scheduled task to run the python script directly have been unsuccessful. The problem is that they do not run the script and do not report an error, and the reason is not found.) the pork_worm.sh content is as follows:

#! / bin/bashpython / opt/price_worms/pork_worm_daily.py

/ usr/local/bin/ python the timing task no longer runs after the upgrade.

It is possible to run sh/ opt/sh/pork_worm.sh directly from the command line. Later, run / opt/price_worms/pork_worm_daily.py error report directly with python

[root@cciikaifa ~] # python / opt/price_worms/pork_worm_daily.pyTraceback (most recent call last): File "/ opt/price_worms/pork_worm_daily.py", line 3, in from bs4 import BeautifulSoupImportError: No module named bs4

Why can't you find module? the fundamental reason is that python2 is not compatible with this version of bs4.

Run directly with python3:

Python3 / opt/price_worms/pork_worm_daily.py starts crawling data 2019-08-16 15:13:40

It's working normally.

The scheduled task has been tried several times but does not run.

Later, the root path of python3 was added to the shell startup script file to work properly.

Input instruction: whereis python3python3: / usr/local/bin/python3.6 / usr/local/bin/python3.6m / usr/local/bin/python3.6m-config / usr/local/bin/python3 / usr/local/bin/python3.6-config / usr/local/lib/python3.6

Then change all sh scripts to run python as follows:

#! / bin/bash/usr/local/bin/python3 / opt/price_worms/pork_worm_daily.py above is how to regularly execute python tasks in the linux system shared by the editor. If you happen to have similar doubts, please refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report