Please help me with my cron job. Immense details inside.

Installing, Configuring, Troubleshooting server daemons such as Web and Mail

Please help me with my cron job. Immense details inside.

Postby Kinsbane » 2010/01/23 02:42:00

I apologize profusely for the umpteenth time this question has been asked, but I have been to the end of the internet and back and tried every solution and I just have not had any luck.

Please forgive me, and see if you can help me out. I will run any command I need to and post back the results.

I don't care what it takes, but I need to stop doing things at the end of every day that should be automated tasks.

PHP is running as CLI-enabled, crond is running, everything is doing what it should, but I just cannot get this script to be run by crontab.

My crontab, where $HOME is: /home/user/
Code: Select all
MAILTO=me@company.com
30 18 * * * /usr/bin/php -f $HOME/retireevents.php



Screenshot of the file in its proper path:
[img]http://www.kinsbane.net/temp/cron-showpathtofile.jpg[/img]

Screenshot of the file permissions:
[img]http://www.kinsbane.net/temp/show-file-perms.jpg[/img]

Screenshot of /usr/bin/php:
[img]http://www.kinsbane.net/temp/usr-bin-php.jpg[/img]

when I type "env" into the terminal, here's what it outputs (information edited a little bit to only deal with entries that weren't pertinent to possible solutions I found on the internet)
Code: Select all
SHELL=/bin/bash
USER=user
MAIL=/var/spool/mail/user
PATH=/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/home/user/bin
PWD=/home/user
HOME=/home/user
LOGNAME=user
LESSOPEN=|/usr/bin/lesspipe.sh %s
G_BROKEN_FILENAMES=1
_=/bin/env


I *know* all of this information is 100% correct.

Yet, I am getting emails from the Cron Daemon that say this:
From: root@thunder
Subject: Cron /usr/bin/php -f $HOME/retireevents.php
Date: January 22, 2010 6:33:01 PM PST
To: me@company.com
------------------------------------------------------------------------------------------
Could not open input file: /home/user/retireevents.php


Now, the path listed in the email is the EXACT SAME path listed in the cron job itself, and you can also verify that by the screenshot I posted above.

But yet, I still am getting emails telling me that Cron "Could not open input file".

I just need help to fix this so I can take a huge weight off my shoulders. I am spending upwards of an hour at the end of every day doing other people's repetitive tasks that should be handled automagically by the server itself.

I really, REALLY need your help.

Thank you so much in advance for any assistance you can offer.
Kinsbane
 
Posts: 11
Joined: 2010/01/23 02:14:07

Re: Please help me with my cron job. Immense details inside.

Postby AlanBartlett » 2010/01/23 14:19:18

Either try --

Code: Select all
MAILTO=me@company.com

30 18 * * * /bin/bash -c "/usr/bin/php -f /home/user/retireevents.php"

-- for your crontab file OR create a script file, let's call it retirement_time, mode 755, with contents --

Code: Select all
/usr/bin/php -f /home/user/retireevents.php

-- and a crontab file like --

Code: Select all
MAILTO=me@company.com

30 18 * * * /path/to/retirement_time

-- and see how things behave.
User avatar
AlanBartlett
Forum Moderator
 
Posts: 8975
Joined: 2007/10/22 11:30:09
Location: ~/Earth/UK/England/Suffolk

Re: Please help me with my cron job. Immense details inside.

Postby Kinsbane » 2010/01/25 19:37:36

Hi Alan,

Thanks for the response!

I ran the first option (which specified using /bin/bash -c) and it still fired off an email that said it could not open the file.

I then tried the second option of making a script file and doing it that way, and this is the email i got back from the CRON daemon:
/bin/sh: /home/user/retirement_time
: No such file or directory


I'm not entirely sure I made the script file correct, does it need a .sh extension?
Kinsbane
 
Posts: 11
Joined: 2010/01/23 02:14:07

Re: Please help me with my cron job. Immense details inside.

Postby pschaff » 2010/01/25 20:11:14

Not Alan; however, no .sh is required; that is simply a frequent convention. The script does have to be executable (chmod +x retirement_time), but lack of that would give a different error like:
Code: Select all
sh: /home/user/retirement_time: Permission denied


The error you are seeing says the file does not exist at the path you supplied.
pschaff
Retired Moderator
 
Posts: 18277
Joined: 2006/12/13 20:15:34
Location: Tidewater, Virginia, North America

Re: Please help me with my cron job. Immense details inside.

Postby Kinsbane » 2010/01/26 00:19:45

pschaff wrote:
Not Alan; however, no .sh is required; that is simply a frequent convention. The script does have to be executable (chmod +x retirement_time), but lack of that would give a different error like:
Code: Select all
sh: /home/user/retirement_time: Permission denied


The error you are seeing says the file does not exist at the path you supplied.


Hi, thanks for the reply.

I am unsure how else to proceed here - I've made doubly sure that my paths are all 100% correct. I've even tried using the $HOME variable to no luck.

Have you looked at my first post where I listed the ENV variables and what they are? They all match up. Those are all valid paths, and all valid files with correct permissions.

But this is why I am posting this question here - it's because I cannot find a viable answer anywhere else on the internet, and my Google skills are not lacking.

What else do I do when I am frustrated that I have followed instructions explicitly and verified thrice over that all files and paths and permissions are correct, yet I do not see the results I am expecting in return?

Is there anything I should investigate that I might have overlooked? Something with the shell, or with cron itself?

I had heard that cron's default path for files to execute is the /home/user folder which is set as $HOME when I list the var's with ENV. But if I specify my own path, shouldn't that override the look to the /home/user folder?
Kinsbane
 
Posts: 11
Joined: 2010/01/23 02:14:07

Re: Please help me with my cron job. Immense details inside.

Postby pschaff » 2010/01/26 02:33:14

Please show the results of
Code: Select all
ls -lF /home/user/retirement_time /home/user/retireevents.php
cat /home/user/retirement_time
cat /home/user/retireevents.php
pschaff
Retired Moderator
 
Posts: 18277
Joined: 2006/12/13 20:15:34
Location: Tidewater, Virginia, North America

Re: Please help me with my cron job. Immense details inside.

Postby Kinsbane » 2010/01/26 18:53:03

Hi pschaff,

Here's straight from the terminal.

Thank you!
Code: Select all
OpenSSH_5.2p1, OpenSSL 0.9.7l 28 Sep 2006
Last login: Mon Jan 25 11:40:23 2010 from 192.168.7.201
[jshaw@thunder ~]$ ls -lF /home/jshaw/retirement_time /home/jshaw/retireevents.php
-rwxrwxrwx 1 jshaw jshaw 1126 Jan 22 17:48 /home/jshaw/retireevents.php*
-rwxr-xr-x 1 jshaw jshaw   44 Jan 25 11:40 /home/jshaw/retirement_time*
[jshaw@thunder ~]$ cat /home/jshaw/retirement_time
/usr/bin/php -f /home/jshaw/retireevents.php[jshaw@thunder ~]$ cat /home/jshaw/retireevents.php
#!/usr/bin/php
<?php
$link = mysql_connect("localhost","dbuser","dbpass");
mysql_select_db("design_center");

$endofevent = $row['event_date'] + ($row['event_length'] * 86400);
$sql = "SELECT * FROM event WHERE event_status = 'on schedule' AND event_date < '".time()."'";
$res = mysql_query($sql);
$mailbody = '';
while ($row = mysql_fetch_array($res))
{
        $eventtime = $row['event_length'] * 86400;
        $endofevent = $row['event_date'] + $eventtime;
        if(time() > $endofevent)
        {
                $nq = "UPDATE event SET modified_by='John Shaw(automatic)', event_status='over' WHERE event_id='$row[event_id]'";
                if($res2 = mysql_query($nq))
                {
                        $mailbody .= '<p>The event #'.$row['event_id'].' called "'.$row['event_title'].'" was modified successfully. End of this event: '.date("M j, Y", $endofevent).' </p>';
                }

        }
}
$headers = "From: Design Center Events Manager <eventsmanager@designcenter.mrv.com>\n";
        $headers .= "X-Priority: 3\n";
        $headers .= "X-Mailer: PHP/".phpversion()."\n";
        $headers .= "Content-type: text/html; us-ascii\n";
mail("jshaw@mrv.com", "Events Modified", $mailbody, $headers);
[jshaw@thunder ~]$
Kinsbane
 
Posts: 11
Joined: 2010/01/23 02:14:07

Re: Please help me with my cron job. Immense details inside.

Postby pschaff » 2010/01/26 19:49:12

Your error message was
Code: Select all
    /bin/sh: /home/user/retirement_time
    : No such file or directory


"user" != "jshaw"
pschaff
Retired Moderator
 
Posts: 18277
Joined: 2006/12/13 20:15:34
Location: Tidewater, Virginia, North America

Re: Please help me with my cron job. Immense details inside.

Postby Kinsbane » 2010/01/26 20:59:10

pschaff wrote:
Your error message was
Code: Select all
    /bin/sh: /home/user/retirement_time
    : No such file or directory


"user" != "jshaw"


I replaced everything with user instead of jshaw because I didn't want people on the internet reading my name.

But then I decided screw it, I just need it fixed. So I pasted directly from the terminal, which included my actual username on the server.

I assure you, if you replace "user" with "jshaw" with everything in my first post, all the errors would be there.

It's the same problem. And it's not related to /home/user/ or /home/jshaw/.

There is no /home/user/. There is, however, /home/jshaw/ and there IS /home/jshaw/retirement_time and there IS /home/jshaw/retireevents.php

See?
[img]http://www.kinsbane.net/temp/home-jshaw-is-real-not-an-error.jpg[/img]

I know what I am doing. And I know that this problem is not as simple as misplaced files, because the files are there.
Kinsbane
 
Posts: 11
Joined: 2010/01/23 02:14:07

Re: Please help me with my cron job. Immense details inside.

Postby michaelnel » 2010/01/26 21:02:49

Could you please just use the command line and utilities like "ls" instead of pasting all that gui junk into the messages? At least for me, the gui stuff makes it more difficult to read the information.... to the point where I don't want to read it.
michaelnel
 
Posts: 1479
Joined: 2006/05/29 16:50:11
Location: San Francisco, CA

Next

Return to CentOS 5 - Server Support

Who is online

Users browsing this forum: No registered users and 0 guests