[英]crontab doesn't execute my python script
I'm trying to add my python script into cron so it executes every minute 我正在尝试将我的python脚本添加到cron中,以便每分钟执行一次
This is my python code: 这是我的python代码:
#!/usr/bin/env python
import urllib2
from urllib2 import urlopen
import zipfile
import os.path
from time import sleep
import csv
import re
import urllib
import os
class Tor_class:
def __init__(self, s ,ip_tor_file,name):
url = ip_tor_file
request = urllib2.Request(url, headers={"Accept" : "text/html"})
webFile = urllib2.urlopen(request)
localFile = open(url.split('/')[-1], 'w')
localFile.write(webFile.read())
webFile.close()
localFile.close()
self.name_ = name
self.counter = 0
def updateDB():
ip_Tor = Tor_class('\n','''http://torstatus.blutmagie.de/ip_list_exit.php/Tor_ip_list_EXIT.csv''',"Tor")
os.rename('Tor_ip_list_EXIT.csv','Tor_ip_list_EXIT.txt')
if __name__ == "__main__":
updateDB()
when I put this script in cron by using crontab -e 当我通过使用crontab -e将此脚本放入cron时
* * * * * /tmp/download.py
It doesn't do anything. 它什么也没做。
It is all works just fine when I do it in a commend line like that: 当我在这样的推荐行中这样做时,一切都很好:
$ /tmp/download.py
Does anyone have a clue why It doesn't work? 有人知道为什么它不起作用吗?
First, you have an odd indentation in the line with if __name__ ==...
- guess you should check it in your script. 首先,
if __name__ ==...
, if __name__ ==...
有一个奇数的缩进-猜您应该在脚本中检查它。 Then, make sure with what current directory your script runs, AFAIK it is your $HOME - this is where the file would appear. 然后,确保您的脚本运行在哪个当前目录中,AFAIK是您的$ HOME-这是文件出现的位置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.