I am trying to execute a php script in my linux server. the script will run everyday at 8 am. I have uploaded my crontab in linux server and the php file update1.php Script in my crontab is given below. But this isnt updating my databse. where am i doing wrong ? Am i missing something here. Thanks in advance.
crontab
0 8 * * * http://www.mywebsite.com/update1.php
You can use --spider option of wget for this purpose.
0 8 * * * wget --spider http://www.mywebsite.com/update1.php
--spider indicates not to download anything (we just want to go through the pages, that’s all)
This line/code in your crontab:
http://www.mywebsite.com/update1.php
is not an execution of the script, it's just the url to it. You should download the php script, and put it locally on your linux server. That would make things simpler and much more reliable.
I would login to your linux server, use wget to download the script, chmod it to make sure it's executable, and mv it to wherever you want on your server:
wget http://www.mywebsite.com/update1.php -O update1.php
chmod 755 update1.php
mv update1.php /path/to/where/you/want/script
Then now that you have the script locally on your linux server, edit your crontab (crontab -e), and add the following line:
0 8 * * * /path/to/where/you/want/script/update1.php
Related
Alright so I'm having an issue.
I've setup this correctly but something is out of order
I added this to my crontab
* * * * * /home/website/public_html/ && php artisan schedule:run >> /dev/null 2>&1
Now if I start this command from my terminal it will work, but on the crontab log I get this
/bin/sh: /home/website/public_html/ : is a directory
After the frequency of the execution (in your case five stars to run every minute) crontab syntax expects to find the command to run.
I guess you want change the working directory before running php, so you need to add cd to change directory:
cd /home/website/public_html/ && php artisan schedule:run
Anyway, there is plenty of examples and explanations about crontab in internet.
I am running a bash script that transfers files to my AWS bucket.If i run the bash script through my terminal it works fine (via ./myBash.sh).
However I put it in my crontab but there it doesn't work.This is my bash script
#!/bin/bash
s3cmd put /home/anonymous/commLogs.txt s3://myBucket/
echo transfer completed
echo now listing files in the s3 bucket
s3cmd ls s3://myBucket/
echo check
And this is my crontab-
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
46 13 * * * /bin/bash myBash.sh
And here is a list of things i have aready tried -
1)tried running the crontab with a node app to test whether crontab was working(the answer was yes)
2)tried running the crontab without the SHELL and PATH
3)Tried running the bash script from cron using sudo (46 13 * * * sudo myBash.sh)
4)tried running the bash without the /bin/bash
5) Searched many sites on the net for an answer without satisfactory results
Can anyone help me with what the problem may be?(I am running Ubuntu 14.04)
After a long time getting the same error, I just did this :
SHELL=/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin
* * * * * /bin/bash /home/joaovitordeon/Documentos/test.sh
For anyone coming to this post.
I was having same problem and reason was crontab was running under root user and s3cmd was configured under ubuntu user.
so need to copy .s3cfg to root
cp -i /home/ubuntu/.s3cfg /root/.s3cfg
I use let's encrypt for getting certificates and I want to setup renewal for certificates.
So, I decided to check if cron works fine.
I created three file in daily.hourly folder:
test-h:
/sbin/ifconfig >/home/bitnami/ipt
test-h2:
#!/bin/bash
/sbin/ifconfig > /home/bitnami/ipt2
test-h3.sh:
#!/bin/bash
/sbin/ifconfig >/home/bitnami/ipt3
But, I don't see my files in home directory. How to properly use cron.daily?
PS. The cron servive is started, I checked.
I restarted it also just to make sure that changes is applied.
The crontab file contains record for cron.hourly:
17 * * * * root cd / && run-parts --report /etc/cron.hourly
I am not linux guy, so, if it possible get me detailed answer please.
The problem is you didn't chmod +x your scripts. That's needed to make them executable.
I set the following cron tab when I'm under root user.
* * * * * wget -q --spider http://mytargeturl.com/my/url/
The codes are under the same server but owned by another user (and I couldn't set a crontab with that user). I have to request the page with wget because of MVC link system complexity.
When I run:
crontab -l -u root
I can see this crontab setting.
Why would be the reason that crontab doesn't work?
Thanks.
Your syntax looks fine and this should work. Check /var/log/cron to make sure that it is indeed running, and if so, consider logging the command's output to a file and then inspect the file to pinpoint where the problem may be.
Trying to add a new cronjob to my server using Plesk. I have two running already, but it's so long since I set them up that I can't remember why I did it the way I did. They work exactly as they should.
*/13* * * * &> /dev/null php -q httpdocs/forum/notifyreply.php
*/9 * * * * &> /dev/null php -q httpdocs/forum/notifytopic.php
However, when I add my new job using the same format, it doesn't seem to do anything. The script doesn't run and I get no e-mail notification to tell me that the script has run. The new job is as follows:
* * * * * &> /dev/null php -q httpdocs/crm/autoMessages/autoEmail.php
I'm running these on a Linux Virtual Server with Apache and using Plesk Control Panel. Hosting provider is 123-Reg.
Can anyone help?
Thanks!
UPDATE
So I've now removed the /dev/null line so I receive e-mail notifications and I'm getting the following error message:
/bin/sh: php: Permission denied
What I don't understand is why permission is being denied on this command but not on the other two...
Not sure what could have happened, but first thing I would do is to check if the permissions for the new php script are the same as what the old ones have. Do a ls -l on both httpdocs/forum/notifyreply.php and httpdocs/forum/notifytopic.php, and compare the permissions against what httpdocs/crm/autoMessages/autoEmail.php have.
You are not setting a User/Group for the cron command, better do it like this
* * * * * www-data www-data php -q httpdocs/crm/autoMessages/autoEmail.php > /dev/null 2>&1
(assuming that www-data is the correct User)
note that I put the error handling at the end.
Also, I think that you should use the full path; either you forgot to add a slash ( /httpdocs/.... ) , or do you have this script in the cron folder?