Why does only one of the cron jobs not run - php

So I got around to needing cron jobs. So I wrote the cron but now i only see that it fails all the time.
This is the cron:
* * * * * /usr/bin/wget -q -O temp.txt http://fetch.project-sato.net/statuschecker/performcheck.php?key=insertyourkeyhere
I replace the url cause its smth no one here needs to know about and yes I confirmed that the url works because a bought webserver of my friend runs the cron without a problem.
The error im getting:
May 23 20:36:00 DoomMachine-v1 systemd[1]: cron-root-2.service: main process exited, code=exited, status=8/n/a
May 23 20:36:00 DoomMachine-v1 systemd[1]: Failed to start [Cron] "* * * * * wget -q -O temp.txt http://fetch.project-sato.net/statuschecker/performcheck.php?key=insertyourkeyhere".
May 23 20:36:00 DoomMachine-v1 systemd[1]: Unit cron-root-2.service entered failed state.
If I run the command of the cron in the terminal it works fine but the cron seems to have a problem.
Can anyone help me?

Maybe you should write full path to temp.txt file instead of relative, for example /tmp/temp.txt

Related

Cron job does not execute a php file

I have setup a cron job thusly:
*/15 * * * * root /usr/bin/php5.6 /var/www/example.com/cr.php
(Yes, root is owner for now - I'll fix that later)
I have also tried with -q after .../php5.6
but it doesn't seem to be working, even though syslog shows it executes every 15 minutes - for example:
Dec 20 17:45:01 e2e-53-27 CRON[2601]: (root) CMD (root /usr/bin/php5.6
-q /var/www/example.com/cr.php)
If I execute the part after the username 'root' at the bash prompt it does work.
This is apache2 running on Debian. I don't know if this makes any difference but the PHP file is using curl to call an external API that sends an SMS.
You should use this format in cron file to make it work:
*/15 * * * * /usr/bin/php5.6 /var/www/example.com/cr.php
And the best way is to put this in script and add as first line in the script command:
. /root/.bash_profile
to make the environment as it is in command line

Cron is not executing files

I have a php file to execute every minute but when I am running it on command line it executes as expected, but when set to cron job it does not run. Below mentioned are things which I have checked:
cron service
service crond status
crond (pid 183872) is running...
Checked logs of cron execution :
May 21 00:27:01 spartans CROND[194123]: (root) CMD (/usr/bin/php /home/dev/my.php)
May 21 00:27:01 e2e CROND[194122]: (root) MAIL (mailed 84 bytes of output but got status 0x004b#012)
CronJob list in crontab -e
*/1 * * * * /usr/bin/php /home/dev/my.php
My request is to help me in finding error where things are getting wrong. I have started cron service couple of times.

Elastic Beanstalk - Cron job is running but not executing

This is my very first time running a cron job on Elastic Beanstalk (EB). After deploying my code, it seems the cron job is created and running but the PHP script is not executing correctly. Here's my set-up.
In my .ebextensions folder I have a file called 01run.config.
container_commands:
01_remove_old_cron_jobs:
command: "crontab -r || exit 0"
02_cronjobs:
command: "cat .ebextensions/cron_jobs.txt > /etc/cron.d/cron_job && chmod 644 /etc/cron.d/cron_job"
leader_only: true
In my .ebextensions folder I also have a cron_jobs.txt file. Please note that I have an line break at the end of this file as instructed by another stackoverflow post. In my example below I am running the command as ec2-user but I also tried root.
* * * * * ec2-user /usr/bin/php -q /var/app/current/tests/cron.php
After deploying my code, I can see that the file /etc/cron.d/cron_job has been created. I can also see the cron job running every minute when I run sudo tail /var/log/cron.
[ec2-user#ip-xxx-xxx-xxx-xxx ~]$ sudo tail /var/log/cron
Apr 13 12:54:53 ip-xxx-xxx-xxx-xxx crontab[26093]: (root) DELETE (root)
Apr 13 12:55:01 ip-xxx-xxx-xxx-xxx crond[1230]: (*system*) RELOAD (/etc/cron.d/cron_job)
Apr 13 12:55:01 ip-xxx-xxx-xxx-xxx CROND[26128]: (ec2-user) CMD (/usr/bin/php -q /var/app/current/tests/cron.php)
Apr 13 12:56:01 ip-xxx-xxx-xxx-xxx CROND[26139]: (ec2-user) CMD (/usr/bin/php -q /var/app/current/tests/cron.php)
Within /var/app/current/tests/cron.php I have some code that adds a row to a MySQL database (hosted on RDS). But nothing is being added to the database.
I then tried running the cron command directly through my terminal window:
$ /usr/bin/php -q /var/app/current/tests/cron.php
And it runs without error and adds the record to the database. I am logged in as ec2-user in terminal.
Have I missed something? Or is my cron job code set-up incorrectly?
I had a similar problem with a php script that was trying to access an AWS RDS database. Is your php script getting the database details with $_SERVER['RDS_xxxx']? If so, those RDS_xxxx variables don't exist in the environment when the php script is run by cron.
In order to fix this, I added the variables to the beginning of the cron file:
RDS_HOSTNAME=<my_database_hostname>
RDS_PORT=<my_database_port>
RDS_USERNAME=<my_database_username>
RDS_PASSWORD=<my_database_password>
RDS_DB_NAME=<my_database_name>
* * * * * php /path/to/my/script.php
Login via SSH and check if generated cron job file/etc/cron.d/cron_job have unix line ending i.e. ASCII text not win i.e. ASCII text, with CRLF line terminators.
To check the line ending refer the answer here.
Note: If you have windows line ending then you will have to convert the line ending of file .ebextensions/cron_jobs.txt, for that you can use dos2unix or similar program.
I had a similar problem with my RDS_ variables on AWS, I followed this discussion and it works.
This was my cronjob before:
RDS_HOSTNAME=<my_database_hostname>
RDS_PORT=<my_database_port>
RDS_USERNAME=<my_database_username>
RDS_PASSWORD=<my_database_password>
RDS_DB_NAME=<my_database_name>
* * * * * cd /var/app/current && bin/cake notifications send_push >> /var/tmp/notifications.log 2>&1
And changed to this:
* * * * * . /opt/elasticbeanstalk/support/envvars cd /var/app/current && bin/cake notifications send_push >> /var/tmp/notifications.log 2>&1
And now I can access them like: $_SERVER['RDS_HOSTNAME']

How to find the error which is causing a segmentation fault in a script run by cron job

I have a cron job that executes once per day:
0 20 * * * /usr/bin/wget --timeout=10800 -O /home/File.txt http://www.site.com/script.php
and so far all was fine, but recently I found out the script just stops.
I looked in the /var/log/httpd/error_log (it's a CentOS) and found this:
[Thu Nov 21 21:30:32 2012] [notice] child pid 8985 exit signal Segmentation fault (11)
Now, this means two things: the script was successfully running for about hour and a half, but then the segmentation fault happened. Ususally the script takes around 2 hours to complete, so it lacks around half an hour to complete it's job.
Now, I can't find the error which causes the script to stop even though I do have error_reporting turned on.
I'm wondering, is there some way so that I can find a potential error line which caused the script to terminate?
I did try google, and SO, ofc, and tried to achieve the same as on this question here on SO by doing this:
0 20 * * * /usr/bin/wget --timeout=10800 -O /home/File.txt http://www.site.com/script.php 2>1& >> /home/log.txt
but the log file is empty. I'm not so good at managing linux so it may be that my command is wrong in this cronjob, so please steer me right.
Try this
0 20 * * * /usr/bin/wget --timeout=10800 \
-O /home/File.txt http://www.site.com/script.php >> /home/log.txt 2>&1
the 2>&1 part tells to send the STDERR to the same place as STDOUT.
Cron sends the output of the command to the email of the user which is executing it.
For this system to work you must have a mail daemon installed, such as exim or postfix.
Also, you are asking wget to write a file in the /home/ directory, i presume as non-root, which means you can't do that. And if you are root you shouldn't do that.

Cronjob php script not working

I'm trying to set a cronjob to run every 20 minutes.
This works manually:
php /srv/www/mysite.co.uk/public_html/PP/Make_XML.php LONDON
I tried to use "crontab -e" and set it even to every 20 minutes with:
*/20 * * * * php /srv/www/mysite.co.uk/public_html/PP/Make_XML.php LONDON
it was saved to /tmp/crontab.0xYhei9m/crontab
And it doesn't seem to work.
What's wrong here?
EDIT:
Current stats:
*. cron is up and running:
root 31855 1 0 08:39 ? 00:00:00 /usr/sbin/cron
*. Running "crontab -l" shows:
*/20 * * * * /usr/bin/php /srv/www/mysite.co.uk/public_html/PP/Make_XML.php
LONDON
And still no go. Again manually running the script works just fine.
is the cron daemon even running?
it was saved to /tmp/crontab.0xYhei9m/crontab
Yes - that's the file you just edited - its NOT the file crond reads to fire jobs. Crontab whould then read this file, install the updated crontab in the location where crond looks for it and notify crond it needs to process the file.
Have you checked:
crond is running?
your uid is allowed to schedule cron jobs (usually via /etc/cron.allow / /etc/cron.deny)
that the script really isn't being started by cron and failing due to a permissions error?
that the version of crond you are using support $PATH and can find the executable?
In case this is already online, try using wget instead of php, with the url instead of the path, ie.:
*/20 * * * * wget http://YOUR_IP/~YOUR_USER/PATH/Make_XML.php
or
*/20 * * * * wget http://mysite.co.uk/PP/Make_XML.php
First make sure the url works , just by opening it with a browser
Hope it helps!
Crontab doesn't know anything about PATH variable. So use absolute path to your php (/usr/bin/php for e.g.)/ You can run command which php to find your php path

Categories