Como posso definir uma variável PATH de todo o sistema para o cron no Centos 6.4

1

Eu gostaria de ter certeza de que cada crontab específico do usuário tenha o mesmo ambiente PATH. Eu tentei definir o caminho em / etc / crontab mas parece que este arquivo de configuração não é lido por crond.

A seguir estão os pacotes relacionados ao cron que estão instalados na minha máquina:

root@machine:~> rpm -qa | grep cron
cronolog-1.6.2-10.el6.x86_64
cronie-anacron-1.4.4-7.el6.x86_64
cronie-noanacron-1.4.4-7.el6.x86_64
crontabs-1.10-33.el6.noarch
cronie-1.4.4-7.el6.x86_64

UPDATE: meu / etc / crontab

desculpa pela resposta tardia.

SHELL=/bin/bash
PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin"
MAILTO=root
HOME=/

# For details see man 4 crontabs

# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name command to be executed
    
por john.dough 24.06.2013 / 16:47

1 resposta

0

Tem certeza de que está definindo o $PATH corretamente? Dê uma olhada em man 5 crontab :

An  active  line in a crontab will be either an environment setting or a cron com‐
mand.  The crontab file is parsed from top to bottom, so any environment  settings
will affect only the cron commands below them in the file.  An environment setting
is of the form,

    name = value

where the spaces around the equal-sign (=) are optional, and any  subsequent  non-
leading  spaces  in  value  will be part of the value assigned to name.  The value
string may be placed in quotes (single or double, but matching) to preserve  lead‐
ing  or  trailing  blanks.  To  define an empty variable, quotes must be used. The
value string is not parsed for environmental substitutions or replacement of vari‐
ables, thus lines like

    PATH = $HOME/bin:$PATH

will not work as you might expect. And neither will this work

    A=1
    B=2
    C=$A $B
There will not be any subsitution for the defined variables in the last value.

An alternative for setting up the commands path is using the fact that many shells
will treat the tilde(~) as substitution of $HOME, so if  you  use  bash  for  your
tasks you can use this:

     SHELL=/bin/bash
     PATH=~/bin:/usr/bin/:/bin
    
por 24.06.2013 / 17:07