hello friends , I just don't know , why in using Crontab it don't execute a code python that contain :

execfile("Backup1.py")

my code is nouveau_fichier2.py :

#!/usr/bin/python
#-*- coding:Utf-8-*-
# -*- coding: cp1252 -*-

import os

print 'helo'
#os.system("sudo chmod 777 /home/ismail/Bureau/Test/20111214") 
execfile("Backup1.py")

and my crontab file after "crontab -e" is :

# m h  dom mon dow   command

02 16 14 12 3 python /home/ismail/Bureau/nouveau_fichier2.py

And if I replace nouveau_fichier2.py par Backup1.py directly it execute it and do the backup , I need your help pythonians please .

and in the log file in this time i find :

Dec 14 16:16:01 pbadmin-desktop cron[954]: Error: bad hour; while reading /etc/crontab
Dec 14 16:16:01 pbadmin-desktop cron[954]: (openerp_user) ORPHAN (no passwd entry)
Dec 14 16:16:01 pbadmin-desktop cron[954]: (user) RELOAD (crontabs/user)
Dec 14 16:16:01 pbadmin-desktop CRON[3877]: (user) CMD (python /home/user/Bureau/nouveau_fichier2.py )

Use subprocess not execfile

#!/usr/bin/python
#-*- coding:Utf-8-*-
# -*- coding: cp1252 -*-
 
import os
import subprocess
 
print 'hello'
#os.system("sudo chmod 777 /home/ismail/Bureau/Test/20111214") 
subprocess.call("/path/to/program/Backup1.py", shell=True)

There are many, many docs on the web about subprocess if you want to know more, as it is used in many different ways.

Edited 4 Years Ago by woooee: n/a

Hello firends , good morning woooee , thank u for your good answer , i tried the command and its working good in executing nouveau_fichier2.py like

./nouveau_fichier2.py

, I'll try now to put it in a crontab and tell you the result :)

Hello again woooee , I've just tried : ok , I try some solutions now , thank you

With crontab it is good , i could planify to execute Backup1.py from nouveau_fichier2.py in a cron job .
Now , i need it to be executed by Anacrontab : Anacrontab is a tool that can check if there is some missing jobs of crontab while the computer is off for exemple , and execute these jobs after the next start by 2 or 3 or 5 minutes ( depend on the configuration you like ) , well It works good for Backup1.py , but when i want it to work for executing nouveau_fichier2.py (that execute Backup1.py inside by : "

#
subprocess.call("/path/to/program/Backup1.py", shell=True)

, it don't work , can you see why please ? thank you very much

Hello friends , I could finaly execute a python code with arguments from an other python code using Anacrontab .

This article has been dead for over six months. Start a new discussion instead.