运行 使用 P4 的 crontab 作业

Run crontab job with P4

我有一个 shell 脚本,它又调用了一个 python 脚本。但是在 python 脚本 运行s 之前,我正在设置环境变量以便获得正确的 P4 配置。

shell: /home/ag/ump_prod/run.sh
python script: /home/ag/ump_prod/cron.py
Environment conf: /home/ag/ump_prod/env.conf

python脚本通过subprocess模块​​执行命令行P4命令。 这是 shell 脚本

的代码
#!/bin/sh
. /home/ag/ump_prod/env.conf
python /home/ag/ump_prod/cron.py

env.conf

export SHELL=/bin/bash
export USER=ag
export MAIL=/var/mail/ag
export HOME=/home/ag
export LOGNAME=ag
export P4CONFIG=/home/ag/ump_prod/.perforce

perforce 配置 /home/ag/ump_prod/.perforce :

P4CLIENT=ag_ump
P4EDITOR=/usr/bin/vim
P4PORT=rsh:ssh -2 -q -a -x -l p4server p4.****.com /bin/true
P4USER=ag

手动 运行 宁 shell 脚本执行它没有任何问题。 但是,当我通过 cronjob 运行 它抱怨它无法连接到服务器时。

错误信息:

['TCP receive failed.\n', 'read: socket stdio: Connection reset by peer\n', 'Perforce client error:\n', '\tTCP receive failed.\n', '\tread: socket stdio: Connection reset by peer\n']

请告诉我在为 P4 配置设置环境变量时哪里可能出错。提前致谢!

我找到了解决方案:我还需要为 cronjob 动态启动 ssh-agent。这就像您第一次登录并启动 ssh-agent 一样。我们也需要告诉 cronjob 包括 eval ssh-agent