Jump to content

Crontab from PHP


dyluck

Recommended Posts

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
https://forums.phpfreaks.com/topic/208784-crontab-from-php/#findComment-1090759
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
https://forums.phpfreaks.com/topic/208784-crontab-from-php/#findComment-1090933
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
https://forums.phpfreaks.com/topic/208784-crontab-from-php/#findComment-1090942
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.