Page 1 sur 4

script python via la crontab

Publié : 22 nov. 2018, 22:32
par vr6man
Je souhaite lancer via la crontab un script python

si je lance en console

sudo /usr/bin/python2.7 /home/pi/domoticz2/scripts/python/cozytouch.py

le script fonctionne par contre en sudo crontab -e:


*/1 * * * * /home/pi/domoticz2/scripts/python/cozytouch.py

ne fonctionne pas

j'ai aussi essayé


*/1 * * * * python2.7/home/pi/domoticz2/scripts/python/cozytouch.py
*/1 * * * * sudo python2.7/home/pi/domoticz2/scripts/python/cozytouch.py
*/1 * * * * /usr/bin/python2.7/home/pi/domoticz2/scripts/python/cozytouch.py

Merci de votre aide ca je seche

Re: script python via la crontab

Publié : 22 nov. 2018, 23:15
par papoo
bonsoir
a tu essayé ?

Code : Tout sélectionner

*/1 * * * * python /home/pi/domoticz/scripts/python/cozytouch.py
ou

Code : Tout sélectionner

*/1 * * * * sudo python /home/pi/domoticz/scripts/python/cozytouch.py
avec toujours un espace entre python et le chemin vers ton script cozytouch.py

Re: script python via la crontab

Publié : 22 nov. 2018, 23:18
par vr6man
oui ca ne fonctionne pas

Re: script python via la crontab

Publié : 23 nov. 2018, 14:20
par patrice
Bonjour
crontab -e et non pas sudo crontab -e
N'est ce pas ?
puis
*/10 * * * * sudo /home/pi/domoticz/scripts/le_nom_du_script.py /home/pi/domoticz/scripts/le_nom_du_script.py

Re: script python via la crontab

Publié : 23 nov. 2018, 18:06
par vr6man
j'ai mis


*/2 * * * * sudo /home/pi/domoticz2/scripts/python/cozytouch.py /home/pi/domoticz2/scripts/python/cozytouch.py

et ca ne marche pas non plus

Re: script python via la crontab

Publié : 23 nov. 2018, 20:20
par oredin
Bonjour,

De manière générale, évitez d'utiliser "sudo" dans les commandes Cron. Normalement, "sudo" est sensé vous demander un mot de passe de temps en temps (même si ce n'est pas le cas par défaut sur les distributions Pi).

Ceci étant dit, si votre script doit s'exécuter en "root", en modifiant la crontab via "sudo crontab -e", la ligne suivante devrait fonctionner pour exécuter votre script toutes les minutes :

Code : Tout sélectionner

* * * * * /usr/bin/python2.7 /home/pi/domoticz2/scripts/python/cozytouch.py
Bon courage

Re: script python via la crontab

Publié : 23 nov. 2018, 20:54
par vr6man
ok je viens de mettre

*/2 * * * * /usr/bin/python2.7 /home/pi/domoticz2/scripts/python/cozytouch.py

ca ne fonctionne pas non plus

Re: script python via la crontab

Publié : 23 nov. 2018, 23:04
par digdogger
attention,
sudo crontab -e et crontab -e n'éditent pas le même fichier.

Chez moi, je fais:
crontab -e
puis ma ligne:
0 */6 * * * /usr/bin/python /home/pi/domoticz/scripts/python/monscript.py >/dev/null 2>&1

Re: script python via la crontab

Publié : 24 nov. 2018, 08:57
par vr6man
Voici ma crontab et je n'ai que celle la

Les autres scripts sont bien lancé via cette crontab

*/2 * * * * /usr/bin/python2.7 /home/pi/domoticz2/scripts/python/cozytouch.py
*/5 * * * * /home/pi/domoticz2/scripts/nas.sh
#*50 23 * * * /home/pi/domoticz2/scripts/jf.sh
*/15 * * * * /home/pi/domoticz2/scripts/get_rain_probability.sh
*/10 * * * * /home/pi/freebox/freebox_infos.sh

quel est l'intéret de >/dev/null 2>&1 a la fin de la ligne ?

Re: script python via la crontab

Publié : 24 nov. 2018, 10:22
par mike913
Bonjour
Moi je lance des scripts python via crontab.
Les scripts python doivent commencer par les lignes:

Code : Tout sélectionner

#!/usr/bin/env python
# coding=UTF-8
# ----------------------------------------------------------------------------
ensuite ils doivent être exécutables
ensuite dans le crontab j'ai les lignes:

Code : Tout sélectionner

@reboot	/usr/local/sbin/Boot
@weekly	./py/ArchiLog.py
@daily	./py/SysLog.py
2	0	*	*	*	./py/purge.py
mes scripts sont dans le répertoire /home/user/py