Cron is not Running for my laravel 5 project - linux

This question may be duplicate (CronJob not running) however, it does not resolve my issue. Let me explain this. By seeing the post in https://laravelcode.com/post/laravel-55-task-scheduling-with-cron-job-example , I wanted to set the cronjob via terminal. I see from FTP that artisan has set in the path: /var/www/html/projectName/
and I believe that this server is Ubuntu. I ran this below command but did not happen anything.
* * * * * /var/www/html /var/www/html/projectName/artisan schedule:run 1>> /dev/null 2>&1
From the above mentioned stackoverflow post, I ran the command ps ax | grep cron which return me:
1013 ? Ss 0:57 /usr/sbin/cron -f
19067 pts/0 S+ 0:00 grep --color=auto cron
I believe the path of cronjob is set as wrong. But how can I rectify this, I can't understand. Any help is appreciated.

I run this command and it works well
* * * * * php /var/www/html/projectName/artisan schedule:run >> /dev/null 2>&1
From: http://www.expertphp.in/article/laravel-5-task-scheduling-with-cron-job-example

Related

Cron won't execute none of my commands on Ubuntu 21.10 impish

I'm trying to run a Docker container every other minute that is stopped via cron job but it seems not working.
What I've done is launch the command crontab -e and add the line
*/1 * * * * docker start sender >> /home/cronlog.log 2>&1
I've added the user group to Docker as explained here (in fact I can access docker from the terminal without sudo)
I have also tried to add the command into a script as below
*/1 * * * * /home/start_container.sh >> /home/cronlog.log 2>&1
with the script containing
#!/bin/sh
docker start sender
but still, nothing happens. The cron process is working tho as using the command ps -ef | grep cron I got
root 881 1 0 08:42 ? 00:00:00 /usr/sbin/cron -f -P
nicola 10905 10178 0 11:31 pts/0 00:00:00 grep --color=auto cron
Am I missing something? (Obviously, the commands work if launched manually from the terminal)
Try using the docker path instead.
type the following command to get the path of docker.
$ where docker
/usr/bin/docker
/bin/docker
then try any one of the paths in the cron script
*/1 * * * * /bin/docker start sender >> /home/cronlog.log 2>&1
or
*/1 * * * * /usr/bin/docker start sender >> /home/cronlog.log 2>&1
It turned out that, for some reason, the cron doesn't like the /home/ (at least, in this specific instance)
I've fixed using another path such as
*/1 * * * * docker start sender >> /tmp/cronlog.log 2>&1

Cronjob stopped executing

I used the crontab before but cannot get any command running anymore.
I am editing directly via crontab -e and testing with simple commands like
* * * * * echo "hello there" >> /Users/myUsername/Desktop/test.txt
Running this command ps -ef | grep cron | grep -v grep gives me this output:
0 270 1 0 6Sep20 ?? 0:00.61 /usr/sbin/cron
Today is 22Sep20. Did the crontab stop running?
My shell is zsh on MacOS.
On MacOS run crontab -l to list all installed cron scripts
or crontab -l -u [user] for another user.
Your * * * * * syntax means it's running every minute and that looks all fine to me. Check syntax here

crontab is not working properly with scrapy

I've set crontab to execute scrapy script, but It is not work.
then I attempt same command in terminal. but It is work well.
rankAuction
crontab:
$ crontab -l
*/10 * * * * cd ~/PRG/tutorials/tutorials/spiders && scrapy crawl nodecrawler
How can i solve this issue? please answer this question
thank you
Check your Cron logs to see whats going on
grep CRON /var/log/syslog
You must be getting Unknown command Scrapy or similar error
I am sure its because Scrapy is not in PATH
To fix it, do this
In your Terminal type echo $PATH
Copy the output and then go into crontab -l
Now at the top of that file do this
PATH=<PASTE WHAT YOU COPIED IN LAST STEP>
Your crontab does not know scrapy location
which scrapy will tell you the location of scrapy e.g. "/usr/local/bin/scrapy"
Change to */10 * * * * cd ~/PRG/tutorials/tutorials/spiders && /usr/local/bin/scrapy crawl nodecrawler > /var/log/cronscrapy.log 2>&1
/usr/local/bin/scrapy will make scrapy work properly
> /var/log/cronscrapy.log will create a log at "val/log/cronscrapy.log" when your cron will run
2>&1 will output both standard output and error if any to the "cronscrapy.log"
Hope it helps someone
`

bash script doesn't work through crontab

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

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

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?

Resources