crontab PATH and USER

后端 未结 5 1773
野性不改
野性不改 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:49

    According to "man 5 crontab" you can set environment variables in your crontab, by writing them before your cron lines.

    There is also an example of a crontab so you just have to copy/paste it :

    $ man 5 crontab | grep -C5 PATH | tail 
    # and files in /etc/cron.d. These files also have username fields,
    # that none of the other crontabs do.
    
    SHELL=/bin/sh
    PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
    
    # m h dom mon dow usercommand
    17 * * * *  root  cd / && run-parts --report /etc/cron.hourly
    25 6 * * *  root  test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
    47 6 * * 7  root  test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
    

    So you can adjust your PATH or any environment variable to whatever you want. But this example seems enough for typical cases.

提交回复
热议问题