簡體   English   中英

在Google Compute Engine VM上的crontab中安排Python腳本

[英]Schedule a Python script in crontab on Google Compute Engine VM

我已經安排了我的Python腳本每小時執行一次,方法是在外殼程序中鍵入crontab -e ,然后將此文本行添加到cron文件中:

0 * * * * /usr/bin/python /home/myUserName/automatedProject/test.py &>> /home/myUserName/automatedProject/log.txt

但是無論我嘗試什么變化,它都不會執行。

作為測試腳本,我使用Jessica Yung的簡單腳本將時間戳附加到文件:

#! /usr/bin/env python
import time
filename = "record_time.txt"
current_time = time.strftime('%a %H:%M:%S')
with open(filename, 'a') as handle:
    handle.write(str(current_time))
    handle.write('\n')

在帶有Ubuntu 16.04 VM的Google Compute Engine中,似乎根本沒有啟動用戶級的cron作業。 但是,根級作業按預期方式工作。

而不是像這樣編輯crontab:

crontab -e

使用sudo crontab -e

一個簡單有效的示例是* * * * * /usr/bin/python /home/myUserName/test.py ,每分鍾運行一次test.py

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM