Cron job to retrieve email

This plugin allows you to report an issue in MantisBT by sending an email to a particular mail account

Moderators: Developer, Contributor

Post Reply
nolankam
Posts: 9
Joined: Dec 30, 2018 2:33 am

Cron job to retrieve email

Post by nolankam » Jan 07, 2019 9:57 am

I have checked and confirmed that my configuration for the mailbox is correct by executing the bug_report_mail.php on command prompt (I am using the Bitnami package running on Ubuntu on AWS).

But I am not able to get the cronjob to run properly.

The following is my statement in crontab:

Code: Select all

*/1* * * * * root /opt/bitnami/apps/mantis/htdocs/plugins/EmailReporting/scripts/bug_report_mail.php
This is the result:

Code: Select all

From: root@-removed- (Cron Daemon)
To: root@i-removed-
Subject: Cron <root@-removed-> /opt/bitnami/apps/mantis/htdocs/plugins/EmailReporting/scripts/bug_report_mail.php
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin>
X-Cron-Env: <HOME=/root>
X-Cron-Env: <LOGNAME=root>
Message-Id: <-removed->
Date: Mon,  7 Jan 2019 14:47:01 +0000 (UTC)

/opt/bitnami/apps/mantis/htdocs/plugins/EmailReporting/scripts/bug_report_mail.php: 1: /opt/bitnami/apps/mantis/htdocs/plugins/EmailReporting/scripts/bug_report_mail.php: cannot open ?php: No such file
/opt/bitnami/apps/mantis/htdocs/plugins/EmailReporting/scripts/bug_report_mail.php: 2: /opt/bitnami/apps/mantis/htdocs/plugins/EmailReporting/scripts/bug_report_mail.php: Syntax error: "(" unexpected
Installed postfix and got the logs from /var/mail.

I have checked and from the bug_report_mail.php is in the stated folder. I am able to execute it on command prompt without any problems. Ran out of ideas. Anyone know how to fix this crontab? I've also tried to point to the PHP folder which is found in /opt/bitnami/php/bin.

SL-Gundam
Posts: 576
Joined: Jul 06, 2011 9:17 am

Re: Cron job to retrieve email

Post by SL-Gundam » Jan 07, 2019 1:19 pm

Its advised to call PHP first before the php file to be run

See here: https://github.com/mantisbt-plugins/Ema ... L.txt#L121

nolankam
Posts: 9
Joined: Dec 30, 2018 2:33 am

Re: Cron job to retrieve email

Post by nolankam » Jan 07, 2019 10:36 pm

I have done so. However, I am getting errors in the permissions.

Code: Select all

From: root@-removed- (Cron Daemon)
To: root@-removed-
Subject: Cron <root@-removed-> /opt/bitnami/php/bin /opt/bitnami/apps/mantis/htdocs/plugins/EmailReporting/scripts/bug_report_mail.php
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/root>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=root>
Message-Id: <20190108032201.1B60382AF6-removed->
Date: Tue,  8 Jan 2019 03:22:01 +0000 (UTC)

/bin/sh: 1: /opt/bitnami/php/bin: Permission denied
I made these changes using sudo crontab -e. Previously, I had also tried to edit the crontab file in /etc but received the same errors. I had also check the permissions for /opt/bitnami/php to make sure it is executable.

cas
Posts: 668
Joined: Mar 11, 2006 11:08 am
Contact:

Re: Cron job to retrieve email

Post by cas » Jan 08, 2019 3:49 am

What we found in the past that it is best to change to the right directory first like:

cd \Sites\mantis\plugins\EmailReporting\scripts
G:\php\php.exe bug_report_mail.php

Perhaps that can help you :mrgreen:

SL-Gundam
Posts: 576
Joined: Jul 06, 2011 9:17 am

Re: Cron job to retrieve email

Post by SL-Gundam » Jan 08, 2019 12:48 pm

I've never used bitnami. I suggest you ask bitnami support how to call PHP from cronjob

In my opinion it should work since you are trying to run the job as root. Which should give you all necessary permissions

nolankam
Posts: 9
Joined: Dec 30, 2018 2:33 am

Re: Cron job to retrieve email

Post by nolankam » Jan 08, 2019 8:17 pm

Thanks. Issue is closed.

Edited the crontab file in /etc into the following

Code: Select all

*/1* * * * *  bitnami /opt/bitnami/php/bin/php/opt/bitnami/apps/mantis/htdocs/plugins/EmailReporting/scripts/bug_report_mail.php
The only change I made was to add the additional php in the path of the php binary. Seems to work now.

Post Reply