crontab PATH and USER

后端 未结 5 1784
野性不改
野性不改 2020-11-27 15:29

I am new to scheduling tasks with cron and crontab. I am trying to schedule execution of a task as if I had logged on, opened a terminal, and executed it myself.

Ho

5条回答
  •  时光说笑
    2020-11-27 15:39

    Remember crontab is a daemon or service, so is not like a user logged in or something. If you want to have your environment variables you will need to set them yourself. However, most of these variables are set by the shell from the /etc/profile path and then going into your custom variables into your $HOME directory.

    You may be able to set some of them by "sourcing" your /etc/profile like:

    41 11 * * * /home//cron_env.sh
    
    Where cron_env.sh will contain something like:
    #!/bin/sh
    source /etc/profile
    /usr/bin/env > /home//cron_env.log
    

提交回复
热议问题