I'm trying to add my python script into cron so it executes every minute
This is my python code:
#!/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
* * * * * /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. Then, make sure with what current directory your script runs, AFAIK it is your $HOME - this is where the file would appear.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.