Search code examples
perlcronperforcecron-task

Cannot run perforce from crontab


I am trying to execute perl script that works with perforce, from crontab. This is my perl code:

print `/usr/local/bin/p4 filelog /projects/config.json`;

I am getting error:

Perforce client error:
    Connect to server failed; check $P4PORT.
    TCP connect to perforce:1666 failed.
    Name or service not known

The same command is working smoothly from cli. Any ideas what can i do with it?


Solution

  • It's because you don't have the P4CONFIG (or alternative) environment vars are set in your cron environment. You simply need to replicate the environment vars you have in your interactive shell (perhaps using set | grep ^P4 to determine what they are).

    Find more details about setting env vars here.