I want to create and remove cronjobs using php. I am using
exec('echo -e "crontab -l\n30 9 29 7 * curl http://myurl/send-cron" | crontab -');
this code to create cron and right now it's working good but I also want to delete specific cron how can i do this and please tell me is this right way to create cron using php
Related
For example I have a cron running on the 1st of every month, this cron executes a PHP script that returns some dates.
I want to use these dates and modify the schedule of another cron job?
I know I can add a new cronjob doing something like this but unsure of how to update 1 specific entry when there could be multiple.
$output = shell_exec('crontab -l');
file_put_contents('/tmp/crontab.txt', $output.'* * * * * NEW_CRON'.PHP_EOL);
echo exec('crontab /tmp/crontab.txt');
Make sure you do not break something you better monitor your cronjobs after you deploy this 😉 But what you want to do is possible.
You can create, modify and delete Cronjobs via PHP (Use PHP to create, edit and delete crontab jobs?)
This is also true if this PHP is executed via another cronjob (as long as you give the correct permissions)
⇒ It is possible (q.e.d.)
Also see this question: https://askubuntu.com/questions/408611/how-to-remove-or-delete-single-cron-job-using-linux-command
This is how you remove a single cronjob (by example) - just create a new one for the different dates:
crontab -u mobman -l | grep -v 'perl /home/mobman/test.pl' | crontab -u mobman -
I am currently making single calls to scripts that do the same thing and was wondering if there is a command to make cron run all links in a page?
link 1
link 2
link 3
link 4
I'm quite new to this but I have searched the net for an answer but maybe I'm not searching for the right terms.
in linux platform you can edit the cron file directly by
crontab -e or sudo crontab -e and teh cron file you can put a file to run on each line with the interval for itself
see :
https://askubuntu.com/questions/2368/how-do-i-set-up-a-cron-job
This question already has answers here:
Cron Job with Laravel 4
(4 answers)
Closed 7 years ago.
I am trying to develop a cron job for a command I have already created. I am completely new to cron jobs so I dont really know how it works.
Trying the command by myself in the console works perfectly. All I need is to be able to execute it every 24 hours. I am using Laravel 4, can anyone help?
Thanks!
To create a cron job as root, edit your cron file:
[sudo] crontab -e
Add a new line at the end, every line is a cron job:
25 10 * * * php /var/www/<siteName>/artisan <command:name> <parameters>
This will execute the same command at 10:25AM everyday.
Just make sure you keep a blank line after the last one. And you also might need to use the full path of your php client:
25 10 * * * /usr/local/bin/php /var/www/<siteName>/artisan <command:name> <parameters>
You could register your cron job like this:
php /path/to/your/laravel/project/artisan your-custom-command
See my answer on this question, my example is for L3 but should work for Laravel 4 accordingly.
I am using Ubuntu server, and I want to do a wget cron job for just about every day of the week for different files.
I have gotten this to work for only one task, but anytime I try to do more it automatically overwrites the old one. I know how to set up times, and the format, etc; but I do not know how to do multiple wget cron jobs.
This is how I've been doing only one so far:
echo "*/10 * * * 5 wget http://XXX.XXX.XXX/files/thursday.php" | crontab -
Can anyone help me? Thanks
best to use the command line crontab function for maintaing cron jobs
crontab -e
will bring up the editor.
The default on most *nix system is vi, which is not newbie friendly, but you can change it to nano or pico with
export EDITOR=nano
and if your on a system like mine, your logged in user may not be the best user to run cron jobs as; so you may may have to use su to switch users before editing the crontab file.
looking at what you are specify doing, unless you really need to go through appache, you can just call the php file like so "php file.php" no wget needed.
*/10 * * * 5 php FULL_PATH/files/thursday.php > /dev/null 2>&1
hi i am working on send email every day 10am so i search lot of sites so i find using crone then it's possible to send email actually iam new to using crone so how can i install crone in my server please provide me some samples on sending email using php with crone.
Thanks for advance.
cron is probably already installed on your server. you will access it with:
crontab -e
To make it email with php you will probably want to use something like this: http://pear.php.net/package/Net_SMTP/
Cron is the inbuilt functionality provided by linux. it is a task scheduler. you need to set the cron to execute a php script every day at 10 am. this php script will contain the code for sending emails.
To see already set cron jobs use crontab -l to set new cron jobs use crontab -e. Your cron job looks as follows
1 2 3 4 5 /path/to/command arg1 arg2 OR 1 2 3 4 5 /root/backup.sh
Where,
1: Minute (0-59)
2: Hours (0-23)
3: Day (0-31)
4: Month (0-12 [12 == December])
5: Day of the week(0-7 [7 or 0 == sunday])
/path/to/command - Script or command name to schedule
Check this link for more details How to Cron jobs
Also you may need to set the path to php executable in your php script, something like
#!/path/to/php/executable
as cron is Linux command it need to know which program to use to execute the given script. the above line goes as a first line before opening php tags.
Setup the cronjob:
$>crontab -e # this command line command sets up the cronjob and opens the vi editor
Linux Crontab Format
MIN HOUR DOM MON DOW CMD
Vi editor opens: add your script there:
Example:
25 11 * * * .csh 2014_09_16 --> This will execute the csh script daily at 11:25am and send an email accordingly
Esc- Shift+zz to exit the editor by saving the changes
$>crontab -l # this cmd checks if the conjob is set
You can easily execute a PHP file using cronjobs, and let it take care of your email sending. I've written a tutorial here: http://rapliandras.hu/blog/how-to-execute-php-scripts-as-cronjobs/
If you are unsure of how exactly an email is sent using PHP, check out its mail function's documentation here: http://php.net/manual/en/function.mail.php