Why is my cron job not running? - linux

I am trying to run a cron job at 5:20pm as below but it's not working.
20 17 * * 1 /usr/bin/php /home/myacc/public_html/job/generate.php
I basically did crontab -e and entered the above line there and saved the file.
If I try running the command directly from the command line as below, it works fine:
php /home/myacc/public_html/job/generate.php
What am I doing wrong?
Also, how do I send a message from the cron to either a log file or email so that I know what's going on?

You can record all the logs of your cronjobs by installing postfix and configuring it as local domain during installation. Such that you can see the logs of your cron jobs by vi /var/mail/<user-name>. Try looking the logs and figure out the problem. If you don't find any solution post the log so that it will help others to diagnose the problem. I'm adding this as an answer instead of comment because i think I'm answering your second query.

Related

Cronjob won't execute on 1and1 server

I have 1and1 web hosting. I am supposed to be able to set up cron jobs using crontab to execute on the server. I have a job set up as follows (including showing the full path to my PHP installation):
(uiserver):u*******:~ > which php5.4
/usr/local/bin/php5.4
(uiserver):u*******:~ > crontab -l
20 * * * * /usr/local/bin/php5.4 /kunden/homepages/40/d*******/htdocs/job.php
If I execute the command manually in the terminal, it runs fine. But the cron job never runs.
Am I missing something obvious?
I've tried checking the cron logs, but I just get permission denied, unfortunately, so that was no help for troubleshooting. The joys of being on somebody else's server, I guess...

Entry in cron.d not executed

I have a cron task configured in cron.d directory that would get executed for every 5 minutes. The entry is
*/5 * * * * root /usr/sbin/logrotate /etc/logrotate.d/test_consolelog
This would invoke the logrotate. However the logrotate didn't happen. I checked the /var/log/cron file to see if cron executes the command and could see that the command is getting executed for every 5 minutes.
I tried executing the command mannually on the terminal and could see that the command is executed and log rotation happens.
What could be reason that logrotate is not happening when getting executed from cron.d.
Regars,
Bala
I found the root cause. The SELinux needs to be disabled for this to work. Earlier while testing the sestatus value is disabled in the the /etc/selinux/config file however the current status was enforcing. Once i restarted the vm itself the sestatus updated to disabled and logrotate functioned as desired. prior to that i have fixed the bad minute error too.
I had furnished enough details for this post and done enough research before posting here. However i am not sure why some one marked this post as there is no research effort or unclear or unuseful...

Cronjob on Amazon EC2 Deleted?

I had a cronjob set up to run a php script daily, which went well for about a month. Today, I realized it didn't run the script so I opened up the crontab. The crontab is completely empty - what happened?
I don't know too much about cronjobs, but as far as I understand, they do not delete themselves if the server is reset. How can I make sure cronjobs are always running and that it doesnt get deleted?
It is probably under a different user. Check root user sudo crontab -e. Each user has it's own crontab and there's one for the whole system. Note: Through the crontab configuration you can disable per-user crontabs.

getting No such file or directory error for cron job

I wanted to run the following file from a cron job and got No such file or directory error, please help.
/var/www/vhosts/domain.com/httpdocs/filename.php
Just use a service like WebBasedCron (google it) to schedule your cron job remotely. If you can access the filename.php file from a browser like FireFox, then you can execute the cron job.

File path for a Cron Job

Hi I want to run a cron job to call a PHP script on my server. I am using Cpanel from my web host and these are the options:
Minute:
Hour:
Day:
Month:
Weekday:
Command:
I am really struggling to point the command to my file I am using this line /home/abbeysof/public_html/adi/cron/daily.php but I am getting this error:
/bin/sh: /home/abbeysof/public_html/adi/cron/daily.php: Permission denied
I asked my web host for help and this is the response:
If you use cpanel to create it, it will fill in the path for you. Typically /home/username/public_html/etc
Can anyone please offer some advice?
Advise 1: use wget command, wget runs the PHP script exactly as if it was called from the web so the PHP environment is exactly the same of when calling the file from the web, it's easier to debug your script then.
wget -O - http://yourdomain.com/adi/cron/daily.php >/dev/null 2>&1
The cron jobs has to be created going into cPanel cron jobs menu. I don't understand if you have this clear by reading your hoster's answer.
And advise 2: change web hosting, try this one they don't leave you alone.
Sorry, I don't know anything about cpanel, but it sounds like:
if you created the file daily.php, then you need to change the permissions on it
if they created the file, then there's a bug in their creation routine.
Good luck!
try this one
/usr/bin/php -q /home/yourCpanelUsername/public_html/filename.php
for some cpanels it might be like this
/usr/local/bin/php -q /home/yourCpanelUsername/public_html/filename.php
Sounds like you need to make /home/abbeysof/public_html/adi/cron/daily.php executable.
The link might help you.
https://www.inmotionhosting.com/support/edu/cpanel/how-to-run-a-cron-job
There is difference if you are using VPS than sharing hosting for giving the command.
You may need to use user-agent & cPanel-Cron along with your url.
curl --user-agent cPanel-Cron http://example.com/cron.php

Resources