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.
Related
I have a cron job set up to write a local json file. It should run every hour and over write
previous file. but it is not running unless I run it manually via the cli. Here is how i have set up on the crontab
00 * * * * php /var/www/cron_jobs/pixel_mapping.php >/dev/null 2>&1
the permissions of the php file are
rw-rw-r-- 1 username username 822 Apr 13 11:02 pixel_mapping.php
my user permissions are
drwxrwxr-x
If I run it as php /var/www/cron_jobs/pixel_mapping.php on the cli
it does write to the json file. any ideas or trouble shooting ideas to try and
have this done by the cron?
many thanks
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
one of my cronjobs send an email daily
35 6 * * * cd $EZPUBLISHROOT && $PHP runcronjobs.php -q 2>&1
I stopped cron using
sudo service cron stop
when i check the cron status
sudo service cron status
it is cron stop/waiting
the problem is i stopped my crons yesterday , but today also the email was sent again
am i doing this wrong
1.how to stop all cron jobs properly
2.how to view last ran cronjob list .
i tried to get last ran cronob details by
grep cron /var/log/syslog
but it is empty , but when i go to the syslog file i can see the word CRON in some places .
Aug 12 09:10:01 64177 CRON[6388]: (root) CMD (cd /var/www && /usr/bin/php runcronjobs.p......
also when i tries typing
ps -ax|grep cron
5696 pts/3 S+ 0:00 grep --color=auto cron
13011 ? Ss 0:00 cron l
is it possble to run crons after i stopped the cron jobs ??
Thanks in advnace
The proper way to do it is to put every job or every group of jobs in their own 'namespace' / file:
/etc/cron.d/production-job-mail-on-delivery
/etc/cron.d/production-aggregate-account-data
/etc/cron.d/devel-job-mail-on-delivery
/etc/cron.d/system-cleanup-sundy
/etc/cron.d/common-mailings
When you want to stop, you just move those files out of the /etc/cron.d/ folder.
You should not stop the cron service and you shouldn't use crontab / /etc/crontab on a bigger system.
Why?
For example, I have 200 cronjobs on a system. /etc/crontab file gets very messy. Some jobs need to be stopped for a week for example, others need to run permanently. Using cron.d folder this is a very simple task.
Normally you would access your crontab with:
crontab -l (lists cronjobs)
and to edit:
crontab -e
to stop a cronjob temporarily you can usually just comment out the first digit:
# 35 6 * * * cd $EZPUBLISHROOT && $PHP runcronjobs.php -q 2>&1
to no longer run a cronjob permanently just delete the particular job. crontab usually restarts itself automatically after you edit it. if not trying using:
sudo restart cron
more information: http://man7.org/linux/man-pages/man1/crontab.1.html
The simple way to do it is commenting the cronjob trough a crontab -e:
#35 6 * * * cd $EZPUBLISHROOT && $PHP runcronjobs.php -q 2>&1
Other than that you should configure the time the frequency of the cronjob to run.
To stop processes you can
ps|aux grep runcronjobs
and after you get a list of the processes runing you can just kill a process using its number
kill *number
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']
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.