How to get CRON to call in the correct PATHs

前端 未结 15 1163
时光取名叫无心
时光取名叫无心 2020-11-22 06:07

I\'m trying to get cron to call in the correct PATHs. When I run a Python script from shell the script runs fine as it uses the PATHs set in bashrc but when I use cron all t

15条回答
  •  深忆病人
    2020-11-22 06:51

    I used /etc/crontab. I used vi and entered in the PATHs I needed into this file and ran it as root. The normal crontab overwrites PATHs that you have set up. A good tutorial on how to do this.

    The systemwide cron file looks like this:

    This has the username field, as used by /etc/crontab.
    # /etc/crontab: system-wide crontab
    # Unlike any other crontab you don't have to run the `crontab'
    # command to install the new version when you edit this file.
    # This file also has a username field, 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 user   command
    42 6 * * *   root    run-parts --report /etc/cron.daily
    47 6 * * 7   root    run-parts --report /etc/cron.weekly
    52 6 1 * *   root    run-parts --report /etc/cron.monthly
    01 01 * * 1-5 root python /path/to/file.py
    

提交回复
热议问题