I have a script that is requires a cron job.

The script has the option to run a manual cron job which works fine and the option of seting up an automatic cron job which is where the problem is.

The support from the scripts authors is poor as they can't seem to configure it to run properly and indeed have left me with 2 cron jobs with no explanation when the installation guide suggests only one.

Anyway, the cron isn't doing all the tasks it should and in addition I get an email that has the following message:

TERM environment variable not set.

[36mWelcome to CakePHP v2.0.0-dev Console [0m

App : app

Path: /home/myaccount/public_html/www.mysite.com/app/

Despite asking the authors what this error is I am 'reliably' told it is not an error and to ignore it.

I asked my hosting company and they have replied:

What does the TERM environment variable need set to. I have enabled SSH for you to log in and set environment variable TERM for your account to the desired value. If you are not sure about this, please check with the application/script vendor.

So I am stuck in the middle - one says ignore the other says set it.

I am not sure what/how to do this and would be grateful of any help.

I am hopng that the functions that aren't working with the cron at the moment (some are) will begin to work once this TERM is set.

Hope I have explained this sufficiently as crons/ssh are a mystery to me.

Many thanks in advance

Mark

is it php script?
is it single file script or multiple files?
can u post script code here?

Hi

Do you mean the script that is being run from the cron job?

Mark

Yes

Hi Magicmarkuk,
I believe that's what urtivedi is asking. Please post the script code.

Ok - here goes, I hope these are the correct files:

The cron command is either:

    /home/myaccount/public_html/www.mysite.com/core/cake/console/cake -app /home/myaccount/public_html/www.mysite.com/app cron encode>/dev/null 2>&1 

or

    /bin/sh /home/myaccount/public_html/www.mysite.com/app/vendors/shells/cron.sh >> /home/myaccount/public_html/www.mysite.com/app/tmp/error.log >/dev/null 2>&1

The email I receive has the subject:

Cron /home/myaccount/public_html/www.mysite.com/core/cake/console/cake -app /home/myaccount/public_html/www.mysite.com/app cron encode

So this may give a clue as to which cron job is giving the error.

Now looking at which files are being called - there are 3 files with cron in the title:

cron.php which is in the /app folder

<?php
/**
 *
 * @version $Id: cron.php 870 2009-09-08 12:29:17Z siva_063at09 $
 * @copyright 2009
 */
class CronShell extends Shell
{
    function main()
    {
        // site settings are set in config
        App::import('Model', 'Setting');
        $setting_model_obj = new Setting();
        $settings = $setting_model_obj->getKeyValuePairs();
        Configure::write($settings);
        // include cron component
        App::import('Core', 'ComponentCollection');
        $collection = new ComponentCollection();
        App::import('Component', 'Cron');
        $this->Cron = new CronComponent($collection);
        $option = !empty($this->args[0]) ? $this->args[0] : '';
        $this->log('Cron started without any issue');
        if (!empty($option) && $option == 'encode') {
            $this->Cron->encode();
        }
    }
}
?>

The second is also called cron.sh and in the /app folder

#!/bin/bash

# lock logic for semaphore - http://mywiki.wooledge.org/BashFAQ/045
lockdir=/tmp/cron_sh.lock
echo >&2 "$(date '+%Y-%m-%d %H:%M:%S') #################################################"
if mkdir "$lockdir"
 then    # directory did not exist, but was created successfully
     echo >&2 "successfully acquired lock: $lockdir"

##########################################################################################################

# -----------------------------------------------------------------
# grouponpro  --->
# ==========
/home/vhost1ag/html/getlancer/core/cake/console/cake -app /home/vhost1ag/html/getlancer/app cron encode

##########################################################################################################
    rmdir "$lockdir"
 else
     echo >&2 "cannot acquire lock, giving up on $lockdir"
     exit 0
 fi

Both of the above are in the /app folder

The third file seems to be the file that does all the actions and is also called cron.php but doesn't sit within the /app folder:

<?php
class CronComponent extends Component
{
    var $controller;
    public function encode()
    {
        $this->update_project();
        $this->update_dispute();
    }
    /**********************************************************************
        # get all OpenForBidding, BiddingClosed, FinalReviewPending projects.
        # check bid_end date expired for OpenForBidding projects.
          - projects moved to BiddingExpired which are the projects have no bids.
          - projects moved to BiddingClosed which are the projects have at least one bid.
          - admin alert, send mail for both cases.
        # check bid_end+Project.max_days_to_select_winner date expired for BiddingClosed projects.
          - projects moved to BiddingExpired which are the projects obtain the above conditions.
          - admin alert, send mail for both cases.
        # check payment_completed_date+Project.max_days_to_close_project date expired for FinalReviewPending projects.        
          - projects moved to Completed which are the projects obtain the above conditions.
          - adding full rating for both 
    ***********************************************************************/
    public function update_project()
    {
        App::import('Model', 'Project');
        $this->Project = new Project();
        App::import('Model', 'UserReview');
        $this->UserReview = new UserReview();
        $projects = $this->Project->find('all', array(
            'conditions' => array(
                'Project.project_status_id' => array(
                    ConstProjectStatus::OpenForBidding,
                    ConstProjectStatus::BiddingClosed,
                    ConstProjectStatus::FinalReviewPending,
                )
            ) ,
            'contain' => array(
                'User' => array(
                    'UserPermissionPreference',
                    'fields' => array(
                        'User.id',
                        'User.username',
                        'User.email'
                    )
                ) ,
                'ProjectBid' => array(
                    'conditions' => array(
                        'ProjectBid.is_active' => 1,
                    ) ,
                    'Bid'
                ) ,
                'UserReview'
            ) ,
            'fields' => array(
                'Project.id',
                'Project.user_id',
                'Project.name',
                'Project.slug',
                'Project.bid_end_date',
                'Project.project_status_id',
                'Project.payment_completed_date'
            ) ,
            'recursive' => 2
        ));
        foreach($projects as $project) {
            switch ($project['Project']['project_status_id']) {
                case ConstProjectStatus::OpenForBidding:
                    if (strtotime($project['Project']['bid_end_date'] . ' 23:55:59') <= strtotime(date('Y-m-d 23:55:59'))) {
                        if (!empty($project['ProjectBid'][0]['Bid'])) {
                            $data['Project']['project_status_id'] = ConstProjectStatus::BiddingClosed;
                        } else {
                            $data['Project']['project_status_id'] = ConstProjectStatus::BiddingExpired;
                        }
                        $data['Project']['id'] = $project['Project']['id'];
                        $this->Project->Save($data);
                        if ($data['Project']['project_status_id'] == ConstProjectStatus::BiddingExpired) {
                            $employer_user[] = $project['Project']['user_id'];
                            $return_employer_lists = $this->Project->_sendAlertOnProjectExpired(array_unique($employer_user) , $project, ConstProjectUsers::Employer);
                            // Send mail to admin
                            $this->Project->_sendAlertOnProjectStatusToAdmin($project, $project['Project']['project_status_id'], $data['Project']['project_status_id']);
                        }
                        if ($data['Project']['project_status_id'] == ConstProjectStatus::BiddingClosed) {
                            $employer_user[] = $project['Project']['user_id'];
                            $return_employer_lists = $this->Project->_sendAlertOnProjectClosed(array_unique($employer_user) , $project, ConstProjectUsers::Employer);
                            // Send mail to admin
                            $this->Project->_sendAlertOnProjectStatusToAdmin($project, $project['Project']['project_status_id'], $data['Project']['project_status_id']);
                        }
                    }
                    break;

                case ConstProjectStatus::BiddingClosed:
                    if (strtotime($project['Project']['bid_end_date'] . ' 23:55:59' . '+' . Configure::read('Project.max_days_to_select_winner')) < strtotime(date('Y-m-d 23:55:59'))) {
                        $data['Project']['project_status_id'] = ConstProjectStatus::BiddingExpired;
                        $data['Project']['id'] = $project['Project']['id'];
                        $this->Project->Save($data);
                        if ($data['Project']['project_status_id'] == ConstProjectStatus::BiddingExpired) {
                            $employer_user[] = $project['Project']['user_id'];
                            $return_employer_lists = $this->Project->_sendAlertOnProjectExpired(array_unique($employer_user) , $project, ConstProjectUsers::Employer);
                            // Send mail to admin
                            $this->Project->_sendAlertOnProjectStatusToAdmin($project, $project['Project']['project_status_id'], $data['Project']['project_status_id']);
                        }
                    }
                    break;

                case ConstProjectStatus::FinalReviewPending:
                    $payment_completed_date = explode(" ",$project['Project']['payment_completed_date']);
                    if (((strtotime(date('Y-m-d')) - strtotime($payment_completed_date[0]))/(60 * 60 * 24)) > Configure::read('Project.max_days_to_close_project')) {
                        $message = $project['Project']['name'] . __l(' has been closed');
                        $subject = $project['Project']['name'] . __l(' has been closed');
                        $data['Project']['project_status_id'] = ConstProjectStatus::Completed;
                        $data['Project']['id'] = $project['Project']['id'];
                        $this->Project->Save($data);
                        $review_count = count($project['UserReview']);
                        if ($review_count == 0) {
                            $data['UserReview']['reviewed_user_id'] = $project['Project']['user_id'];
                            $data['UserReview']['user_id'] = ConstUserIds::Admin;
                            $data['UserReview']['project_id'] = $project['Project']['id'];
                            $data['UserReview']['vote'] = 5;
                            $this->UserReview->Create();
                            $this->UserReview->Save($data['UserReview']);
                            $to_user = array(
                                $project['Project']['user_id']
                            );
                            $message_options = array();
                            $message_options['project_id'] = $project['Project']['id'];
                            $message_options['message_type_id'] = ConstMessageType::ProjectClosed;
                            $message_options['is_auto'] = 1;
                            $message_id = $this->Project->Message->sendNotifications($to_user, $subject, $message, $message_options);
                            $data['UserReview']['reviewed_user_id'] = $project['ProjectBid'][0]['user_id'];
                            $data['UserReview']['user_id'] = ConstUserIds::Admin;
                            $data['UserReview']['project_id'] = $project['Project']['id'];
                            $data['UserReview']['vote'] = 5;
                            $data['UserReview']['is_freelancer'] = 1;
                            $this->UserReview->Create();
                            $this->UserReview->Save($data['UserReview']);
                            $to_user = array(
                                $project['ProjectBid'][0]['user_id']
                            );
                            $message_options = array();
                            $message_options['project_id'] = $project['Project']['id'];
                            $message_options['message_type_id'] = ConstMessageType::ProjectClosed;
                            $message_options['is_auto'] = 1;
                            $message_id = $this->Project->Message->sendNotifications($to_user, $subject, $message, $message_options);
                        } else if ($review_count == 1) {
                            $data['UserReview']['reviewed_user_id'] = $project['UserReview'][0]['reviewed_user_id'];
                            $data['UserReview']['user_id'] = ConstUserIds::Admin;
                            $data['UserReview']['project_id'] = $project['Project']['id'];
                            $data['UserReview']['vote'] = 5;
                            $this->UserReview->Create();
                            $this->UserReview->Save($data['UserReview']);
                            $to_user = array(
                                $project['UserReview'][0]['reviewed_user_id']
                            );
                            $message_options = array();
                            $message_options['project_id'] = $project['Project']['id'];
                            $message_options['message_type_id'] = ConstMessageType::ProjectClosed;
                            $message_options['is_auto'] = 1;
                            $message_id = $this->Project->Message->sendNotifications($to_user, $subject, $message, $message_options);
                        }
                    }
                    break;
                }
        }        
    }
    /**********************************************************************
        # get all Open project disputes.
        # check created+dispute.reply_time date expired and dispute_conversation_count == 0 then.
           - close the dispute with favor of created.

    ***********************************************************************/
    public function update_dispute()
    {
        App::import('Model', 'Project');
        $this->Project = new Project();
        App::import('Model', 'ProjectDispute');
        $this->ProjectDispute = new ProjectDispute();
        App::import('Model', 'Message');
        $this->Message = new Message();
        $disputes = $this->ProjectDispute->find('all', array(
            'conditions' => array(
                'ProjectDispute.dispute_status_id' => ConstDisputeStatus::Open
            ) ,
            'contain' => array(
                'Project' => array(
                    'ProjectBid' => array(
                        'conditions' => array(
                            'ProjectBid.is_active' => 1
                        )
                    ) ,
                    'EscrowAccount' => array(
                        'User' => array(
                            'fields' => array(
                                'User.email',
                                'User.id',
                                'User.username',
                            )
                        ) ,
                        'Milestone' => array(
                            'conditions' => array(
                                'Milestone.milestone_status_id' => ConstMilestoneStatus::PayemntRequested
                            ) ,
                            'order' => array(
                                'Milestone.requested_date' => 'asc'
                            ) ,
                            'limit' => 1,
                        )
                    ) ,
                    'User' => array(
                        'fields' => array(
                            'User.email',
                            'User.id',
                        )
                    ) ,
                    'UserReview',
                    'fields' => array(
                        'Project.id',
                        'Project.user_id',
                        'Project.name',
                        'Project.slug',
                        'Project.bid_end_date',
                        'Project.project_status_id'
                    )
                )
            ) ,
            'recursive' => 2
        ));
        foreach($disputes as $dispute) {
            if (strtotime($dispute['ProjectDispute']['created'] . ' +' . Configure::read('dispute.reply_time') . 'days') < strtotime(date('Y-m-d'))) {
                $dispute_conversation_count = $this->Message->find('count', array(
                    'conditions' => array(
                        'Message.project_dispute_id' => $dispute['ProjectDispute']['id'],
                        'Message.project_id' => $dispute['ProjectDispute']['project_id'],
                        'Message.message_type_id' => ConstMessageType::DisputeUnderDiscussion,
                        'Message.is_sender' => 0,
                        'Message.user_id <>' => $dispute['ProjectDispute']['user_id']
                    )
                ));
                if ($dispute_conversation_count == 0) {
                    $project['Project'] = $dispute['Project'];
                    if ($dispute['ProjectDispute']['user_id'] == $dispute['Project']['user_id']) {
                        switch ($dispute['ProjectDispute']['dispute_open_type_id']) {
                            case ConstDisputeOpenType::DisputeOpenEmployer:
                                $this->ProjectDispute->_rework($project);
                                $closetype = ConstDisputeCloseType::CompletGivenWork;
                                break;

                            case ConstDisputeOpenType::DisputeOpenFeedback:
                                $this->ProjectDispute->_closeProject($project, ConstDisputeOpenType::DisputeOpenFeedback);
                                $closetype = ConstDisputeCloseType::EmployerGivenProperFeedback;
                                break;

                            case ConstDisputeOpenType::DisputeOpenFreelancer:
                                $this->ProjectDispute->_refundCancelProject($project);
                                $closetype = ConstDisputeCloseType::ItemNotMatchedProjectDescription;
                                break;

                            case ConstDisputeOpenType::DisputeFreelancerOpenFeedback:
                                $this->ProjectDispute->_feedbackUpdate($project, $project['Project']['user_id'], $dispute['ProjectDispute']['expected_rating']);
                                $closetype = ConstDisputeCloseType::FreelancerGivenPoorFeedback;
                                break;
                        }
                        if ($this->ProjectDispute->updateAll(array(
                            'ProjectDispute.dispute_status_id' => ConstDisputeStatus::Closed,
                            'ProjectDispute.resolved_date' => '"' . date('Y-m-d') . '"',
                            'ProjectDispute.favour_user_type_id' => 1, //employer
                            'ProjectDispute.dispute_closed_type_id' => $closetype,
                        ) , array(
                            'ProjectDispute.id' => $dispute['ProjectDispute']['id'],
                        ))) {
                            $this->ProjectDispute->Project->updateAll(array(
                                'Project.is_dispute' => 0
                            ) , array(
                                'Project.id' => $dispute['ProjectDispute']['project_id']
                            ));
                            $to_user = array(
                                $project['Project']['user_id']
                            );
                            $subject = __l("Dispute Closed");
                            $message = __l("Dispute Closed in favour of Employer");
                            $dispute_id = $dispute['ProjectDispute']['id'];
                            $message_options = array();
                            $message_options['project_id'] = $project['Project']['id'];
                            $message_options['dispute_id'] = $dispute_id;
                            $message_options['message_type_id'] = ConstMessageType::DisputeClosed;
                            $message_options['is_auto'] = 1;
                            $message_id = $this->Message->sendNotifications($to_user, $subject, $message, $message_options);
                            $message_options['is_auto'] = 0;
                            $to_user = array(
                                $project['Project']['ProjectBid'][0]['user_id']
                            );
                            $message_id = $this->Message->sendNotifications($to_user, $subject, $message, $message_options);
                        }
                    } else {
                        switch ($dispute['ProjectDispute']['dispute_open_type_id']) {
                            case ConstDisputeOpenType::DisputeOpenEmployer:
                                $this->ProjectDispute->_refundCancelProject($project);
                                $closetype = ConstDisputeCloseType::EmployerGivingMoreWork;
                                break;

                            case ConstDisputeOpenType::DisputeOpenFeedback:
                                $this->ProjectDispute->_feedbackUpdate($project, $project['Project']['ProjectBid'][0]['user_id'], $dispute['ProjectDispute']['expected_rating']);
                                $closetype = ConstDisputeCloseType::EmployerGivenPoorFeedback;
                                break;

                            case ConstDisputeOpenType::DisputeOpenFreelancer:
                                $this->ProjectDispute->_closeProject($project, ConstDisputeOpenType::DisputeOpenFreelancer);
                                $closetype = ConstDisputeCloseType::ItemMatchedProjectDescription;
                                break;

                            case ConstDisputeOpenType::DisputeFreelancerOpenFeedback:
                                $this->ProjectDispute->_closeProject($project, ConstDisputeOpenType::DisputeFreelancerOpenFeedback);
                                $closetype = ConstDisputeCloseType::FreelancerGivenProperFeedback;
                                break;
                        }
                        if ($this->ProjectDispute->updateAll(array(
                            'ProjectDispute.dispute_status_id' => ConstDisputeStatus::Closed,
                            'ProjectDispute.resolved_date' => '"' . date('Y-m-d') . '"',
                            'ProjectDispute.favour_user_type_id' => 2, //freelancer
                            'ProjectDispute.dispute_closed_type_id' => $closetype,
                        ) , array(
                            'ProjectDispute.id' => $dispute['ProjectDispute']['id'],
                        ))) {
                            $this->ProjectDispute->Project->updateAll(array(
                                'Project.is_dispute' => 0
                            ) , array(
                                'Project.id' => $dispute['ProjectDispute']['project_id']
                            ));
                            $to_user = array(
                                $project['Project']['user_id']
                            );
                            $subject = __l("Dispute Closed");
                            $message = __l("Dispute Closed in favour of") . ' ' . $this->Project->fAlt(ConstAltVerb::SingularCaps);
                            $dispute_id = $dispute['ProjectDispute']['id'];
                            $message_options = array();
                            $message_options['project_id'] = $project['Project']['id'];
                            $message_options['dispute_id'] = $dispute['ProjectDispute']['id'];
                            $message_options['message_type_id'] = ConstMessageType::DisputeClosed;
                            $message_options['is_auto'] = 1;
                            $message_id = $this->ProjectDispute->Message->sendNotifications($to_user, $subject, $message, $message_options);
                            $message_options['is_auto'] = 0;
                            $to_user = array(
                                $project['Project']['ProjectBid'][0]['user_id']
                            );
                            $message_id = $this->ProjectDispute->Message->sendNotifications($to_user, $subject, $message, $message_options);
                        }
                    }
                }
            }
        }
    }
}
?>

Much appreciated

Mark

Are these the files you meant?

Thanks
Mark

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.