Cronjob command not working, despite having the same format as other commands that DO work - linux

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?

Related

Crontab on shared hosting, not being started

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.

cron job not running in goDaddy shared host for laravel 5.2

I am trying to run cron job in my laravel 5.2 application hosted in goDaddy shared host.
I have cPanel access and there I added a cron job, something like this:
* * * * * php /home/path/to/artisan schedule:run 1>> /dev/null 2>&1
But the issue is that the server is not calling schedule action in Kernel.php. The same works fine in my local system.
Can anyone point out the mistake please or suggest some way to accomplish this so that server runs the cron job so as to execute defined commands.
Add path of php binary to cron command.
* * * * * path/php /home/path/to/artisan schedule:run 1>> /dev/null 2>&1
Example : /usr/bin/php
Cpanel Cron job command in laravel godaddy and others are same
/usr/local/bin/php /home/ivlssadmin/public_html/inventoryproject/artisan OpeningStocks:openingstocks >> /dev/null 2>&1
Here what you change follow bellow :
/usr/local/bin/php /home/Your Host User Name /public_html/Sub Domain Name/artisan Command Name:Command Name >> /dev/null 2>&1
if you don't have sub domain you write only public html
Make sure you write the correct command in the schedule action. e.g. $schedule->command('send:followup')
Also check the timezone of the crontab if possible are you using utc timezone in your commands this is the default for most servers.

Crontab doesn't work with wget

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.

Active cron job

I am trying to make a cron job for the first time but i have some problems making it work.
Here is what i have done so far:
Linux commands:
crontab -e
My cronjob looks like this:
1 * * * * wget -qO /dev/null http://mySite/myController/myView
Now when i look in:
/var/spool/cron/crontabs/
I get the following output:
marc root
if i open the file root
i see my cronjob (the one above)
However it doesnt seem like it is running.
is there a way i can check if its running or make sure that it is running?
By default cron jobs do have a log file. It should be in /var/log/syslog (depends on your system). Vouch for it and you're done. Else you can simply append the output to a log file manually by
1 * * * * wget http://mySite/myController/myView >> ~/my_log_file.txt
and see what's your output. Notice I've changed removed the quiet parameter from wget command so that there is some output.

Cron job: problem with crontab, it automatically sending me an email

How can I disable the email on the cron?
Send the standard output (and standard error) of your cron job to /dev/null
* * * * * /some/cron/job 1> /dev/null 2>&1
If you'd prefer a log file, change /dev/null to a real filename instead, but be aware of the security issues. Specifically, if you're running with any sort of privileged account and the log file doesn't already exist, a hacker can pre-create a symlink in place of your log file, pointing at some other file. When your cron job runs the target of the symlink gets overwritten.
You can redirect the output to /dev/null like this:
* * * * * my_command > /dev/null
If an error occurs, you'll still get an email, though.

Resources