Raspbian Cron Job Not Working - php

Hi I have created this cron job in the /etc/crontab file:
*/2 * * * * /usr/bin/php /var/www/html/daily_scripts/store_all_currencies.php.
It doesnt seem to be working I just want my store_all_currencies.php to run every 2 minutes.
I have had a look in /usr/bin/ and there doesnt seem to be a php file? This is probably the reason it isnt working. I am able to run php files from the console so it is definitely installed.

I think you should try like this for executing cron every 2 minutes, but you must have the php script inside /usr/bin/php/ var/www/html/daily_scripts before execute it. format => cron format php path php filename
*/2 * * * * /usr/bin/php/ var/www/html/daily_scripts/store_all_currencies.php
Every 2 minutes : https://crontab.guru/every-2-minutes

Related

Setting up the crontab on amazon ec2 cloud (Linux server)

I need to run a php file on every 2 hours, so i am using this command
* */2 * * * /usr/bin/php /var/www/html/sports/webservices/rss-insert.php
i am also using this
* */2 * * * php /var/www/html/sports/webservices/rss-insert.php
But both are not working. can anyone help me.
Thanks
The crontab you have made will run every minute of every second hour rather than every two hours.
In order to get it to run every two hours you need something like this:
5 */2 * * * /usr/bin/php /var/www/html/sports/webservices/rss-insert.php
which will run it 5 minutes after every second hour e.g 2:05, 4:05...
This is assuming your script is able to run. Try running the command portion from the cron by hand at the command line and make sure it does what you want.
This works for me definitely work for you.
0 0-23/2 * * * php /var/www/html/sports/webservices/rss-insert.php

Run a php script with cron in mac

I am trying to run in mac a php script using cron. I want this php script to run every one minute. I read several sources online and from my understanding is better if I use launchd. In any case, I try to make it work with cron and then if it works fine I might try to use launchd.
So here is what I do:
I wrote this command in a txt file:
* * * * * /usr/bin/php /Applications/MAMP/htdocs/php_test/main_script.php
There I have the path to php (I found it with the "which php" command) and the path to my php script.
I named the txt file: crontasks.txt and I run it through terminal with this command:
crontab /Users/dkar/Desktop/crontasks.txt
When I list the crons (crontab -l) I see that this job is listed. But nothing comes as output every one minute. The output is supposed to be an image stored in a specified folder. What am I missing here?
Thanks in advance
D.
You might have a slight miscomprehension how crond processes the "crontab" files. It would suffice to run the command crontab -e, which would let you edit your personal crontab or you edit the system crontab.
If you use crontab -e it will open the default editor (vi/vim) and you can enter the line:
* * * * * /usr/bin/php /Applications/MAMP/htdocs/php_test/main_script.php
Then you simply save your file. If you want to use the system crontab you will have to edit it directly and enter the line. Additionally the system crontab has one more field for the username. Like this:
* * * * * /usr/bin/php root /Applications/MAMP/htdocs/php_test/main_script.php
On the next full minute your script will be executed by crond.

Cron job using codeigniter on an ubuntu server

I'm having trouble setting up a cron job.
I have a cron job created at a url like so:
myurl.com/cron
When that link is accessed, it is run.
How do I set it so that it runs automatically, every 10 minutes?
I can't figure out how to create a cron job. I know that that's what I need to do, but I can't figure out how to do it for a ubuntu server.
Login via SSH and in the shell, type the following:
crontab -e
Then, place the following line:
*/10 * * * * /path/to/command
Save the file and that command will be called every 10 minutes.

PHP Cronjob does not execute

I am running Ubunutu Linux server, PHP5, Apache2 and am having trouble getting any sort of cronjob to run through the crontab.
I edit the crontab using
crontab -e
I save the file I want to run:
*/5 * * * * php /home/user/public_html/crx/cronx.php
it saves fine. I can run the file from the console and goes through fine. I can't even find any existing logs for the file. I checked cron was running, stopped and started... no change.
The current php file is just a simple test script that inserts a single line into a database.
I checked the permissions for the file and has read and write. Am absolutely stumped. I can't seem to get ANYTHING to run through cron. Is there something I can run to test permissions?
EDIT
I have also tried the following command
/usr/bin/php /home/user/public_html/crx/cronx.php
I used whereis php and which php to locate and confirm it is all running in the right area
You have too many * values for your times.
Also, cron may not have a PATH set up correctly to use PHP.
Instead try:
*/5 * * * * /usr/bin/php /home/user/public_html/crx/cronx.php
Where /usr/bin/php is the actual path to PHP. From the console you can run which php to see the path to the PHP binary you should use.
EDIT: Here are a couple of more things to try in order to troubleshoot:
# see if cron is running just by having it create a file
*/5 * * * * touch /tmp/crontab-$(date +%s)
Another option:
Set the permissions of your PHP script to 755, and change the beginning to:
#!/usr/bin/php -q
<?php
// rest of script
Then change your cron tab to:
*/5 * * * * /home/user/public_html/crx/cronx.php
I'm still not sure if cron is the issue or the running of the PHP script.

How do I use cron to run a database cleaning script?

I have a database with a bunch of links that I want to keep updated. Basically if a link returns a 404 error code I want to remove it from the database. I have a script that I am using however I need to run it manually. How can I make this work using CRON?
in your shell as cron user (or root):
crontab -e
This will bring up your crontab file in your editor. Add a new line something like this:
* */12 * * * /path/to/script
Save/exit the file.
Now for a quick lesson on cronjobs:
-The first 5 arguments in the line tell how often, or when the cron daemon will execute the 6th argument.
-From left-right, arguments represent: minutes, hours, days, weeks, months
-An asterix (*) tells the cron to run on all values of it's associated time measurement (example * * * * * means to run every minute, of every hour, of every week, and of every month!)
In my example, * */12 * * * means to run every 12 hours.
Check out: http://kevin.vanzonneveld.net/techblog/article/schedule_tasks_on_linux_using_crontab/
To run a PHP script with cron you can use the PHP executable and the path to the script.
On most linux systems you want to edit your cron file (the crontab) with the command crontab -e. This will open up a command line based editor and you can just append your new job to the bottom of the file using this format.
<minute> <hour> <day_of_month> <month> <day_of_week> php /path/to/script
If the commands dont work for you let me know what distribution you are using and I can modify the instructions.
/usr/bin/php -q /home/user/public_html/script.php

Categories