dyluck Posted July 24, 2010 Share Posted July 24, 2010 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. Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted July 24, 2010 Share Posted July 24, 2010 Do you want to edit a specific user's crontab or cron jobs run by the system? Quote Link to comment Share on other sites More sharing options...
dyluck Posted July 24, 2010 Author Share Posted July 24, 2010 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 Quote Link to comment Share on other sites More sharing options...
dyluck Posted July 25, 2010 Author Share Posted July 25, 2010 For the life of me, this command will not work. how to i get php to echo the errors (if any?) shell_exec('crontab /home/dyluck/cron/mfd.txt'); Quote Link to comment Share on other sites More sharing options...
dyluck Posted July 25, 2010 Author Share Posted July 25, 2010 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. Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted July 25, 2010 Share Posted July 25, 2010 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* Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.