Crontab-从〜/ .bashrc传递环境变量
我用crontab撞墙...我试图设置一个crontab来运行一个Python脚本,该脚本从〜/ .bashrc收集4个变量
I'v hit a brick wall with crontab... I'm trying to set a crontab to run a python script that gathers 4 variables from ~/.bashrc
请关闭我当前的crontab。
Bellow my current crontab.
SHELL=/bin/bash
BASH_ENV=/home/m.bienias/.bashrc
# m h dom mon dow command
30 12,15,18 * * 1,2,3,4,5 source /home/m.bienias/.bashrc; /usr/bin/python3
/home/m.bienias/skrypty/mail_reporter/Kwanty_bez_eng.py >> /home/m.bienias/cron-log/mail_reporter.log 2>&1```
I have tried ```source /home/m.bienias/.bashrc;``` and ```. /home/m.bienias/.bashrc;```
Any idea what more I've could miss. Please note that I'm not sudo user on the machine where I try do run crontab
的计算机上使用sudo用户
我建议为您的工作创建一个特定的启动包装脚本。
I would recommend creating a specific start wrapper script for your job.
将该脚本命名为运行-Kwanty_bez_eng.sh
并将其存储在 /home/m.bienias/skrypty/mail_reporter /
Name the script something like run-Kwanty_bez_eng.sh
and store it inside /home/m.bienias/skrypty/mail_reporter/
此脚本负责设置环境并开始工作,因此粗略内容如下:
This script is responsible for setting the environment and starting the job, so rough contents would be like:
#!/usr/bin/env bash
# set environment
source /home/m.bienias/.bashrc
# start job
/usr/bin/python3 /home/m.bienias/skrypty/mail_reporter/Kwanty_bez_eng.py
...
我将进一步建议取消对 .bashrc $的依赖。 c $ c>和您的工作。由作业依赖于
.bashrc
可能引起的问题是更改为 .bashrc
可能导致作业失败或行为不正确,并且 .bashrc
就其职责而言是繁忙的文件。因此最好构建一个特定于作业的环境文件,该文件仅包含执行作业所需的最少变量。
I would further recommend to decouple the reliance on the .bashrc
and your job. The problem that can arise by having the job depend on .bashrc
is that changes to .bashrc
can cause the job to fail or behave incorrectly, and .bashrc
is a busy file in terms of responsibilities it serves. So better to build a job-specific environment file that contains only the minimum required variables to execute the job.