[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: [HS] shell et environnement console versus CRON



fabrice régnier <regnier.fab@free.fr>, samedi 15 octobre 2011 - 12:53 :
> salut la liste,
> 
> J'ai cherché la liste adéquate (shell french) pour poster mais je n'ai
> rien trouvé. Alors si quelqu'un peu me re-redonner l'@ de ce NG. merci.
> 
> Sinon, voici mon petit soucis:
> 
> Dans la crontab de l'utilisateur contact, j'ai ceci:
> 
> * */1 * * * [ -z "$(/usr/bin/pgrep -f mon_script.sh)" ] &&
> /home/contact/mon_script.sh
> 
> Ca doit lancer mon_script.sh s'il ne tourne pas déjà.
> 
> La crontab fait bien son boulot car je vois:
> 
> FA:~# grep mon_script.sh /var/log/syslog|tail -n 1
> Oct 15 12:29:01 FA /USR/SBIN/CRON[2837]: (contact) CMD ([ -z
> "$(/usr/bin/pgrep -f mon_script.sh)" ] && /home/contact/mon_script.sh)
> 
> Par contre, mon_script.sh n'est pas exécuté.
> 
> Lorsque j'exécute en console la même commande:
> 
> contact@FA:~$ [ -z "$(/usr/bin/pgrep -f mon_script.sh)" ] &&
> /home/contact/mon_script.sh
> 
> alors, mon_script.sh démarre bien.
> 
> Quelqu'un a une idée de mon erreur ?

Salut,

Pour lancer la commande, cron va lancer un /bin/sh -c la commande, donc dans 
le cas présent, /bin/sh -c [ -z "$(/usr/bin/pgrep -f mon_script.sh)" ] && 
/home/contact/mon_script.sh, et donc, évidemment, le pgrep va donc renvoyer le 
pid du /bin/sh (notamment à cause du -f), et la commande ne sera donc pas 
lancée.
La solution peut donc être d'enlever le -f.

-- 
Florent

Attachment: signature.asc
Description: This is a digitally signed message part.


Reply to: