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. Link to comment https://forums.phpfreaks.com/topic/208784-crontab-from-php/ 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? Link to comment https://forums.phpfreaks.com/topic/208784-crontab-from-php/#findComment-1090737 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 Link to comment https://forums.phpfreaks.com/topic/208784-crontab-from-php/#findComment-1090759 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'); Link to comment https://forums.phpfreaks.com/topic/208784-crontab-from-php/#findComment-1090790 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. Link to comment https://forums.phpfreaks.com/topic/208784-crontab-from-php/#findComment-1090933 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* Link to comment https://forums.phpfreaks.com/topic/208784-crontab-from-php/#findComment-1090942 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.