Tokyoj

Topic: cron_maintenance.php HELP PLEASE

My server is running the cronjob command tab to run cron_maintenance.php with

php/home/SITEUSERNAMEHERE/public_html/JOBBER/cron_maintenance.php>/dev/null2>&1

but the email notification says...

/bin/sh: /dev/null2: No such file or directory

so I tried the following variants but nothing works...
php/home/SITENAMEHERE/public_html/JOBBER/cron_maintenance.php>
php/home/SITENAMEHERE/public_html/JOBBER/cron_maintenance.php
<php/home/SITENAMEHERE/public_html/JOBBER/cron_maintenance.php>

I know the .php file is in the correct directory. And I'm using the Standard Interface.

I understand that by default cron jobs sends a email to the user account executing the cronjob. And to disable this add  >/dev/null 2>&1 to the end of the cron job line .

Would anyone know why it says "No such file or directory"?

The class.Maintenance.php is (yes...it's set to delete jobs after 1 day...for testing purposes)
<?php

class Maintenance
{
    function __construct()
    { }
   
    // delete temporary posts older than 1 days
    public function DeleteTemporaryJobs()
    {
        global $db;
        $sql = 'DELETE FROM jobs WHERE DATEDIFF(NOW(), created_on) > 0 AND is_temp = 1 AND is_active = 0';
        $db->Execute($sql);
    }
   
      public function DeactivateOldJobs()
    {
        global $db;
        $sql = 'DELETE FROM jobs WHERE DATEDIFF(NOW(), created_on) > 1';
        $db->Execute($sql);
    }
}
?>

The cron_maintenance.php is...

<?php
    require_once 'config.php';
    require_once '_includes/class.Maintenance.php';

    $janitor = new Maintenance();
   
    // delete temporary posts older than 2 days
    $janitor->DeleteTemporaryJobs();
    $janitor->DeactivateOldJobs();
?>

---------------
Tokyoj
"You can't build a reputation on what you're going to do." (Henry Ford)
"Insanity is doing the same thing over and over, expecting different results." (Albert Einstein)

Chronos

Re: cron_maintenance.php HELP PLEASE

Using what method are you configuring your cronjob? Through a (web)application or directly from a console or SSH? "php/home/SITEUSERNAMEHERE/public_html/JOBBER/cron_maintenance.php>/dev/null2>&1" doesn't seem like a full command.

Member of Jobberbase Development Team - Implementation and Coding

Visit my Blog: ChronoScripts (JobberBase scripts, support and freelance)
JobBoards: Telefonisch Werk and Top Bijbaan

Tokyoj

Re: cron_maintenance.php HELP PLEASE

To be honest...that's what another member of the forum helped me create.

I don't understand the question...
"Using what method are you configuring your cronjob? Through a (web)application or directly from a console or SSH?"

If you mean server application...I just pasted it into the Cpanel Cronjob Command field using the Standard interface.

Could you ask in another way?
Thanks.

---------------
Tokyoj
"You can't build a reputation on what you're going to do." (Henry Ford)
"Insanity is doing the same thing over and over, expecting different results." (Albert Einstein)

Chronos

Re: cron_maintenance.php HELP PLEASE

Yes, I meant the server application. Since Cpanel should be fully configured for your account already, there shouldn't be any need for the "/dev/null" addition. If you add the cronjob useing the regular method (you can choose advanced too) it should be as simple as:

"php /home/SITEUSERNAMEHERE/public_html/JOBBER/cron_maintenance.php"

Where the username should be replaced by the unix user (not neccesarily the domain or so) and there should be a space between php and /home.

Member of Jobberbase Development Team - Implementation and Coding

Visit my Blog: ChronoScripts (JobberBase scripts, support and freelance)
JobBoards: Telefonisch Werk and Top Bijbaan

Tokyoj

Re: cron_maintenance.php HELP PLEASE

Thanks...didn't have the space after php so fixed that and just ran the job and the notice email states...

X-Powered-By: PHP/5.2.5
Content-Type: text/html; charset=UTF-8

<br />
<b>Notice</b>:  Undefined index:  SERVER_NAME in <b>/home/catusjpn/public_html/JOBBER/config.php</b> on line <b>18</b><br />
[config.php] Cannot determine APP_MAIN_DIR, please set manual and comment this line

...so it seems I'm screwing up the SERVER_NAME. But looking at config.php from Line18 only states 'localhost'
// MySQL + misc settings for local environment
    if ($_SERVER['SERVER_NAME'] == 'localhost')
    {
        define('DB_HOST', 'localhost');

Would the 'unix user' as you call it be the same as the local environment's
'define('DB_USER', 'XXXXXXX');
in config.php?

---------------
Tokyoj
"You can't build a reputation on what you're going to do." (Henry Ford)
"Insanity is doing the same thing over and over, expecting different results." (Albert Einstein)

Chronos

Re: cron_maintenance.php HELP PLEASE

The problem is that the $_SERVER['variable'] data is sent from the web server, and cronjob is initiated from the local machine.

You could try skipping the config.php check for a local or dev installation by replacing the entire if/else case (of ($_SERVER['SERVER_NAME'] == 'localhost')) by just the needed variables (define('DB_HOST')...)

Member of Jobberbase Development Team - Implementation and Coding

Visit my Blog: ChronoScripts (JobberBase scripts, support and freelance)
JobBoards: Telefonisch Werk and Top Bijbaan

Tokyoj

Re: cron_maintenance.php HELP PLEASE

I'm not sure how this is done...

"replacing the entire if/else case (of ($_SERVER['SERVER_NAME'] == 'localhost')) by just the needed variables (define('DB_HOST')...)"

What gets replaced with what?

Is there another way to resolve the issue and get the cronjob running properly?
Thanks for the help. My learning curve is flatting out.

---------------
Tokyoj
"You can't build a reputation on what you're going to do." (Henry Ford)
"Insanity is doing the same thing over and over, expecting different results." (Albert Einstein)

Chronos

Re: cron_maintenance.php HELP PLEASE

Hm. There are multiple $_SERVER variables used within the config.php, so rewriting the entire file doesn't seem like an option for just one script. I think the cronjob file only needs the connection to the database from the config, so if we manually let it connect and skip the config.php it should work.

Give it a try, adjust your cron_maintenance.php to the following (only need to add your server info, as found in the config.php):

Code:
<?php
/**
 * jobber job board platform
 *
 * @author     Filip C.T.E. <http://www.filipcte.ro> <me@filipcte.ro>
 * @license    You are free to edit and use this work, but it would be nice if you always referenced the original author ;)
 *             (see license.txt).
 */

    //Include the DB Class (either use class.Db.php or class.Db.MySql.php)
    require_once '_includes/class.Db.php';
 
    //Define Server variables (same as config.php)
    define('DB_HOST', 'localhost');
    define('DB_USER', 'root');
    define('DB_PASS', '');
    define('DB_NAME', 'jobberbase');
    
    //Make the connection to the database
    $db = new Db(DB_HOST, DB_USER, DB_PASS, DB_NAME);
    $db->Execute('SET CHARSET UTF8')

    //Include the function  for the cronjob
    require_once '_includes/class.Maintenance.php';

    $janitor = new Maintenance();
    $janitor->DeleteTemporaryJobs();
    $janitor->DeactivateOldJobs();

?>

Last edited by Chronos (2009-01-16 12:42:25)

Member of Jobberbase Development Team - Implementation and Coding

Visit my Blog: ChronoScripts (JobberBase scripts, support and freelance)
JobBoards: Telefonisch Werk and Top Bijbaan

Tokyoj

Re: cron_maintenance.php HELP PLEASE

The cronjob has run it's course and the jobs have run through their 1 day posting period.

The cron_maintenance seems to be running properly because CronDaemon is sending the notification email, but the jobs are not being deleted. The content of the notification email is only...

X-Powered-By: PHP/5.2.5
Content-type: text/html

---------------
Tokyoj
"You can't build a reputation on what you're going to do." (Henry Ford)
"Insanity is doing the same thing over and over, expecting different results." (Albert Einstein)

Chronos

Re: cron_maintenance.php HELP PLEASE

My bad, I forgot to include the Db class, so it couldn't connect to the database. I've updated the code above (check the config.php if you use class.Db.php or class.Db.MySql.php)

Member of Jobberbase Development Team - Implementation and Coding

Visit my Blog: ChronoScripts (JobberBase scripts, support and freelance)
JobBoards: Telefonisch Werk and Top Bijbaan

Tokyoj

Re: cron_maintenance.php HELP PLEASE

From config.php made sure to use
require_once '_includes/class.Db.php';
but no change. Still getting same notification email.

X-Powered-By: PHP/5.2.5
Content-type: text/html

I'll register all the jobs and run it fresh.

class.Maintenance.php is still

<?php

class Maintenance
{
   
    function __construct()
    { }
   
    // delete temporary posts older than 1 days
    public function DeleteTemporaryJobs()
    {
        global $db;
        $sql = 'DELETE FROM jobs WHERE DATEDIFF(NOW(), created_on) > 1 AND is_temp = 1 AND is_active = 0';
        $db->Execute($sql);
    }
   
      public function DeactivateOldJobs()
    {
        global $db;
        $sql = 'DELETE FROM jobs WHERE DATEDIFF(NOW(), created_on) > 1';
        $db->Execute($sql);
    }
}
?>

---------------
Tokyoj
"You can't build a reputation on what you're going to do." (Henry Ford)
"Insanity is doing the same thing over and over, expecting different results." (Albert Einstein)

Chronos

Re: cron_maintenance.php HELP PLEASE

You changed the cron_maintenance.php to the version I adjusted (including the Db include this time?) The cronjob will always display empty output as the file doesn't give any visual output (it should just do its queries).

Member of Jobberbase Development Team - Implementation and Coding

Visit my Blog: ChronoScripts (JobberBase scripts, support and freelance)
JobBoards: Telefonisch Werk and Top Bijbaan

Tokyoj

Re: cron_maintenance.php HELP PLEASE

Yep....config.php uses require_once '_includes/class.Db.php'; so included that.

<?php
    //Include the DB Class (either use class.Db.php or class.Db.MySql.php)
    require_once '_includes/class.Db.php';

    //Define Server variables (same as config.php)
        define('DB_HOST', 'localhost');
        define('DB_USER', 'USERNAMEHERE');
        define('DB_PASS', 'PASSWORD');
        define('DB_NAME', 'DBNAMEHERE');
        define('LOCATION', 'local');
        define('ENVIRONMENT', 'dev');
   
    //Make the connection to the database
    $db = new Db(DB_HOST, DB_USER, DB_PASS, DB_NAME);
    $db->Execute('SET CHARSET UTF8')

    //Include the function  for the cronjob
    require_once '_includes/class.Maintenance.php';

    $janitor = new Maintenance();
    $janitor->DeleteTemporaryJobs();
    $janitor->DeactivateOldJobs();

?>

Deleted testing Employers and Jobs, checked the cron.Maintenance.php again, checked the Command Tab and reposted 3 jobs. Will have to wait 24 hrs for results. Hmmm...very strange...It has to be something incredibly simple.

Chronos, thank you for your help.

---------------
Tokyoj
"You can't build a reputation on what you're going to do." (Henry Ford)
"Insanity is doing the same thing over and over, expecting different results." (Albert Einstein)

putypuruty

Re: cron_maintenance.php HELP PLEASE

Hi, guys!

There is an alternative to having to set up a cron job to do the 'house keeping'. But there is a catch: it requires mysql 5.1. As of version 5.1, you can tell mysql to execute queries/stored procedures/etc periodically.

I think it would be easier to do this with mysql because you would just need to run a query to set it up.

I can write a small tutorial here if anyone is interested.

Last edited by putypuruty (2009-01-17 20:11:12)

Tokyoj

Re: cron_maintenance.php HELP PLEASE

Putypuruty,
I have MySQL V5.0.67...too version #'s can't be rounded up...
if you have the time, could you please post the tutorial in the tutorial section?
Others might want know.

Thank you.

---------------
Tokyoj
"You can't build a reputation on what you're going to do." (Henry Ford)
"Insanity is doing the same thing over and over, expecting different results." (Albert Einstein)