Jump to content

Crontab from PHP


dyluck

Recommended Posts

Hi there,

 

How do you edit the crontab file from php?

 

I need to make adjustments to the crontab file from mysql / php

 

where would I start.  I have searched high and low and came up with very little.

Link to comment
Share on other sites

Cron jobs run by the system

basically the main crontab -e

 

Here is what I have so far:

mfd.sh

#!/bin/sh
crontab /home/dyluck/cron/mfd.txt
echo 'CRONTAB HAS BEEN UPDATED'
# end script

 

mfd.txt

0 2 * * * indexer --config /usr/local/sphinx/etc/sphinx.conf --all --rotate
3 2 * * * /usr/local/sphinx/bin/searchd --stop
4 2 * * * /usr/local/sphinx/bin/searchd*

 

cronmfd.php

<? system('sh /home/dyluck/cron/mfd.sh');
?>

 

Basically I figure that I can easily edit a txt file and then envoke a linux shell script from php.

When I invoke my mfd.sh file from SSH it works fine.

When I do it wiht the php command, it doesn't work :(

Link to comment
Share on other sites

well figured this one out on my own.

first of all, it will update the user's cron not the main system cron (still want to figure that one out)

 

Make sure that the cron.deny file doesn't have "nobody" or "whatever user the apache is using" in the list.

make the cron.allow file in the same directory as cron.deny (if its not already there) and do the following:

 

type:

 

nobody

apacheuserid

 

CTRL X to save and Y and enter.

 

to find out what apacheuserid is, do the following in a php file:

 

$result = shell_exec("whoami");

echo "I am $result";

 

once you edit the cron.allow file,

restart cron

 

# /etc/init.d/crond restart

 

Try again and it will write to the user cron file.

 

to find the user's cron file to see if you even have one,  do a  # locate cron

you will see one with your user id.   

 

Link to comment
Share on other sites

Put your cron file in /etc/cron.d/ and the system will run it.  Or you can link to the file in /home/dyluck/cron/ so that it is still writable.  You need to specify the user to run as in the file:

 

0 2 * * * root    indexer --config /usr/local/sphinx/etc/sphinx.conf --all --rotate
3 2 * * * root    /usr/local/sphinx/bin/searchd --stop
4 2 * * * root   /usr/local/sphinx/bin/searchd*

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.