简体   繁体   English

如何:Python脚本每小时执行一次终端命令?

[英]How: Python Script to execute Terminal Command every hour?

我正在尝试使用python脚本重复执行curl命令,是否有更好的方法来执行此类任务?

Below findings can help you in linux environment. 以下发现可以在Linux环境中为您提供帮助。

You can do that with the help of a cron jab. 您可以在cron戳刺的帮助下完成此操作。

Steps to setup a cron job: 设置cron作业的步骤:

  1. Open crontab by the command "crontab -e" on the shell 在外壳上通过命令“ crontab -e”打开crontab

  2. Paste the following in the file and correct the path 0 * * * * /home/sshashank/script.py 将以下内容粘贴到文件中,并更正路径0 * * * * /home/sshashank/script.py

  3. Make sure you have given proper permissions to the folders where python script is going to run, folder where it is going to access(files/logs). 确保您对要运行python脚本的文件夹,要访问的文件夹(文件/日志)具有适当的权限。

  4. Please provide absolute path and not relative path. 请提供绝对路径而不是相对路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从Python脚本在终端中执行命令? - How to execute a command in the terminal from a Python script? 在MacOS上每小时执行一次Python脚本 - Execute Python Script Every Hour on MacOS 让python脚本每小时执行一些功能 - Make python script execute some functions every hour 执行一个从python 2.6脚本中的终端接收参数的终端命令 - Execute a terminal command that takes an argument from terminal in python a 2.6 script 如何每小时休眠我的python脚本 - How to sleep my python script every hour 如何从 python 脚本在新终端中执行 cd 命令并执行附加命令? - How to perform a cd command and execute additional command in a new terminal from a python script? 如何在终端中执行一行 python 脚本? - How to execute a single line of a python script in Terminal? 登录服务器后如何立即在mac终端中执行python脚本中编写的命令 - How to execute the command written in python script in mac terminal immediately after logged in to the server 如何使用Windows Batch脚本执行python terminal命令? - How can you execute python terminal command using a Windows Batch script? 尝试每小时使用crontab运行python脚本,但是python代码的一部分未执行 - Trying to run a python script with crontab every hour, but one section of the python code does not execute
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM