I try to make a program to download from a specific URL a file. Check if exist and rename the original
when I run it with sudo command everything works fine. I said.. wow!! DONE! and when I add it to cron tab... boom! nothing works.
I read a post that says make a script and run it from there so I did
sudo crontab -e -> */5 * * * * /home/pi/guardian/run_update.sh
run_update.sh -> #!/bin/sh sudo /usr/bin/python /home/pi/guardian/updater.py
issues that i get:
- i couldn't rename a file with os.system("sudo mv " + originalfile + ' ' + renamedfile) not error raised
I couldn't rename a file using the os.rename command in both cases crash with no error the same, no errors
*the above error i fix it by using smaller names on variables
os.system("sudo mv " + s1 +' '+s2)
I couldn't store the file downloaded from the web using
:
testfile = urllib.URLopener()
urllib.urlretrieve(s1, s2)
or by using
getfile = urllib2.URLopener(fromwhere+downloadfiles[i])
with open(downloadfiles[i],'wb') as output:
data=getfile.read(4096)
if data:
output.write(data)
else:
break:
Please advice
After many tries i find out that the program run perfect on command line and almost not at all when runing from crontab, so with the technic "try and seek" at the point that i am now, the problem is that i cant store downloaded file
ANSWER from Vikash Singh thanks a lot sir!!
The program was trying to save the downloaded file to "/root" and after that was only a matter of stored location path.