views:

81

answers:

3

Is there a way to find out if Cron Jobs are available on the server? I mean I want to detect this in a PHP script..

A: 
echo `crontab -l`;
Col. Shrapnel
It doesn't show anything..
Adrian M.
@Adrian it can give you an idea. Stackoverflow can show you the way, but it can't solve your problems like magic wand.
Col. Shrapnel
@Col. is that a PHP line of code?
zaf
@zaf it is php line of code that executes external program
Col. Shrapnel
@Col. I didn't down vote but that does not work for me. You sure you don't mean a BASH line of code or something similar? I've never seen something like that in PHP...
zaf
works for me :)
Phill Pafford
@zaf google for the "PHP backtick operator"
Col. Shrapnel
@Col. you got me! Your example returns blank for all system commands. Is it because the feature is disabled by default?
zaf
A: 

You would have to use system() to determine that reliably:

system('crontab --version', $return);
if ($return == 0)
    echo 'The shell command crontab is available';
soulmerge
It doesn't seem to work..
Adrian M.
@Adrian M.: You sure know those relatives that call you to tell that their computer doesn't work. And you know the first thing *you* ask them: *What* doesn't work? Is it generating an error? Is `$return` always 0? Always another value? Is there no crontab installed?
soulmerge
Yes well excuse my noobness.. I only work with php for a week..
Adrian M.
It's not about PHP, it's about asking questions, giving feedback and reporting problems.
soulmerge
A: 

Just remember it's all about permissions on a Linux system, so if the user you're using doesn't have permission to read the file you should get a "File/directory doesn't exists or not found" error.

So my guess is unless you're running this as root or give permission to the user that needs to read cron, you will run into problems.

You could just look for cron files in the cron directory

On a Cent OS 5 server the cron directory id here:

/etc/cron.d/

you can have multiple crons in the directory as well.

You could parse/read the file to see what scripts are configured in cron as well.

Phill Pafford