Crontab Errors

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

Well, I have the PHP auto-delete script working (details in the other thread), but I now have a weird problem. I set the crontab through Cpanel to run it, but it gets errors.

When I run the script in the browser, it runs fine...

What am I doing wrong with crontab?

Although it's set up through Cpanel, it looks like this:

[email protected]
58 23 * * * /path/to/expiredfiles.php
'

So that it runs at 11:58pm nightly.

Here are the errors:

/correct/path/to/expiredfiles.php: ?: No such file or directory
/correct/path/to/expiredfiles.php: //: is a directory
/correct/path/to/expiredfiles.php: include: command not found
/correct/path/to/expiredfiles.php: //: is a directory
/correct/path/to/expiredfiles.php: line 6: syntax error near unexpected token `;'
/correct/path/to/expiredfiles.php: line 6: `connectdb(); '

I'm not sure what's going on, so I'm trying to avoid includes and just have the information in the file and see if the crontab can run the script that way...

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

I need to talk it out, so here goes -- clearly, it doesn't understand include.

AND it doesn't understand my lovely comments.

Can a cronjob run a php script?

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

http://www.webgfxcenter.com/tutorials/tutorials.cfm/155/PHP/

reading this for more information. hopefully someone will be helped by all this chattering.

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

*yeargh* my php is set up as an apache module, so apparently I need to install lynx to use crontab... !?

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

How do I tell if wget is usable? That is apparently the other option. Also, the installation instructions for lynx are totally unreadable to me, anyone have a simpler way to explain them? Can I even install lynx if I don't have command line access?

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

Okay, this is just silly. Rather than install a bunch of things, I think I will rewrite the script in Perl and be done with it.

There are applications that "fake" crontab for php (basically always looking to see if they should have been running a script). I can install Lynx, or convince a sysadmin to activate wget, or convince a sysadmin to make PHP not an Apache module, but CGI instead.

Feel free to interrupt me, eh?

They have: 601 posts

Joined: Nov 2001

/me mutters something about Perl being better than PHP and goes back to sleep. Smiling

Seriously though, if you need a hand rewriting it in Perl let me know. Nearly all servers I've seen have PHP setup as an Apache module -- I honestly didn't know you could have PHP installed stand-alone on your machine to run in your shell.

- wil

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

Yeah, I probably will need help, Wil. It's been a loooooong time since I wrote Perl and I've long since sold my manuals as I moved across the country and they were heavy suckers.

http://www.zerocattle.com/examples/expiredfiles.phps is the php source. Quite frankly, I'm a bit stymied about how to begin, since I've never used Perl with an actual database.

disaster-master's picture

She has: 2,154 posts

Joined: May 2001

LOL...I don't think I have ever seen anyone post 6 times (talking to themselves) before someone steps in and answers. Laughing out loud

I guess that is a disadvantage of knowing more than than most everyone else here huh? Wink

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

Heh, nah, I was just posting as I was learning. Sometimes I need to explain things to someone else in order to figure things out and there wasn't anyone nearby.

I don't think I gave anyone a chance to comment!

They have: 601 posts

Joined: Nov 2001

Ok Suaznne, I'll take a look at the source from my office tomorrow. From what you describe, it should be easy enough -- Perl has the same good support for databases through the DBI set of modules as has PHP.

- wil

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

Hey hold up! No need to rewrite when you just need a simple crontab line...

Depending on how your script needs to run... under apache:
58 23 * * * lynx http://example.com/path/to/file.php
58 23 * * * wget http://example.com/path/to/file.php

not under apache:
58 23 * * * /path/to/php -f /path/to/file.php

on my linux box, php is at /usr/local/php/bin/php

If you're script has any output, you can redirect it with "2>/dev/null/" or any other log file "2>my.log".

Mark Hensler
If there is no answer on Google, then there is no question.

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

oh wow, a new option!!

okay, trying that, thanks, Mark!

Quick Question: what's the difference between running it under apache and not running it under apache?

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

Okay, how do you know where php is?

Edit: nevermind, for my server it's /usr/local/lib/php and I find this by doing the <? php_info() ?> thing, it's the include_path, right?

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

/bin/sh: /usr/local/lib/php: is a directory

Is the new error, with this:

58 23 * * * /usr/local/lib/php -f /path/to/file/expiredfiles.php

? Ideas?

nike_guy_man's picture

They have: 840 posts

Joined: Sep 2000

I think you need to go to the executable PHP directory
Mine is /usr/bin/php
I never was able to get it to work as a standalone executable though.... bleh

Laughing out loud

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

That is the directory, not the binary. So try this path:
/usr/local/lib/php/bin/php

I found the location by doing "whereis php". Which returned "/usr/local/php". I new the binary was "bin/php", so I appended that and used "/usr/local/php/bin/php".

Mark Hensler
If there is no answer on Google, then there is no question.

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

Oh, and the difference...

Say you had a script that required environmental variables (apache settings, etc.). Or you needed information from the client's HTTP Request header. Yadda yadda yadda. Or any interaction whatsoever with a user.

Mark Hensler
If there is no answer on Google, then there is no question.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.