简体   繁体   English

使用P4运行crontab作业

[英]Run crontab job with P4

I have a shell script which in turn calls a python script. 我有一个shell脚本,该脚本又称为python脚本。 But before the python script runs I am setting up the environment variables in order to have the right P4 configurations. 但是在运行python脚本之前,我正在设置环境变量,以具有正确的P4配置。

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

The python script executes command line P4 commands via the subprocess module. python脚本通过子过程模块执行命令行P4命令。 Here is the code for the shell script 这是shell脚本的代码

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

env.conf 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

The perforce config /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

Manually running the shell script executes it without any issues. 手动运行shell脚本即可执行它,而不会出现任何问题。 However, when I run it via cronjob it complains that it cannot connect to the server. 但是,当我通过cronjob运行它时,它抱怨它无法连接到服务器。

Error Message: 错误信息:

['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']

Please let me know where I could be going wrong in setting the environment variables for P4 configs. 请让我知道在为P4配置设置环境变量时可能出错的地方。 Thanks in advance! 提前致谢!

I found the solution: I needed to start the ssh-agent dynamically for the cronjob as well. 我找到了解决方案:我还需要为cronjob动态启动ssh-agent。 It is just like how you login for the first time and start the ssh-agent. 就像您第一次登录并启动ssh-agent一样。 We need to tell cronjob too to include eval ssh-agent 我们也需要告诉cronjob包括eval ssh-agent

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM