Cron doesn't work in Magento1.7 - bash

I use Magento for my shopping, and I want to give all logged-in users have 3% discount for all products, so I wrote a rule, but it only worked for two days and after two days I had to re-apply it again, my Cron setting in Magento admin is:
Generate Schedules Every: 60
Schedule Ahead for:10
Missed if Not Run Within:60
History Cleanup Every:120
Success History Lifetime:120
Failure History Lifetime:120
To solve this problem, I wrote a Cron job in DirectAdmin panel to call cron.sh file in root of Magento (cron.sh is a shell script file that call cron.php), but it did not work properly, please guide me to solve this problem.
Cron job setting in Directadmin panel is:
0 0 * * * /usr/local/bin/php /home/noorantel/domains/nooran.com/public_html/shopping/cron.sh >> /home/noorantel/domains/nooran.com/public_html/shopping/var/logfile.txt

So firstly the Magento cron should run with the following regularity.
*/5 * * * *
This will mean that it will run every 5 mins.
Secondly you seem to mix up what type the file is either you need to run the php version or the bash version but what you seem to be doing is trying to run the bash version with php. Try the following.
*/5 * * * * /bin/sh /absolute/path/to/magento/cron.sh
Or
*/5 * * * * /usr/local/bin/php /absolute/path/to/magento/cron.php

Related

How Can I run a Command after another Command in Laravel

I have many Command class and they are running in background in my Laravel project.
I have a scenario and I want to run one of the after another one.
$schedule->command('mycommand:first')->cron("*/40 * * * *")->withoutOverlapping();
$schedule->command('mycommand:two')->cron("*/40 * * * *")->withoutOverlapping();
they are running every 40 minutes. but I want to run Command two 10 minutes after Command first.
How can I do that?
If you just want to start command 10 minutes after the first command, you have to set properly cron command. So for your example it would be:
$schedule->command('mycommand:first')->cron("*/40 * * * *")->withoutOverlapping();
$schedule->command('mycommand:two')->cron("*/50 * * * *")->withoutOverlapping();
If you want to learn more about those cron settings you can try something like crontab.guru
If you want to run mycommand:two 10 minutes after mycommand:first finished, you have to probably edit mycommand:first to set some timeout and execution of mycommand:second at the end of the command.

"getpwnam() failed" in /bin/sh only when called from cron

Here's the content of my crontab file:
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO="example#example.com"
*/5 * * * * sh /robot/1/master.sh >/dev/null 2>&1
*/5 * * * * sh /robot/2/master.sh >/dev/null 2>&1
*/5 * * * * sh /robot/3/master.sh
*/5 * * * * sh /robot/4/master.sh >/dev/null 2>&1
*/5 * * * * sh /robot/5/master.sh >/dev/null 2>&1
This is the error that keeps showing in /var/log/cron when it tries to run:
crond[669]: (sh) ERROR (getpwnam() failed)
If I run any of these files manually, they work without any issues.
What's wrong with the crontab file?
It surprises me that nobody has the correct answer to this. Today i faced exactly the same problem and google didn't help.
After 2 hours i found that when placing a file in /etc/cron.d the schedule line has to contain an extra option.....
I allways use this for my crontab -e
# Minute Hour Day of Month Month Day of Week Command
# (0-59) (0-23) (1-31) (1-12 or Jan-Dec) (0-6 or Sun-Sat) /my/fancy/script.sh
So it contains 6 items.
When placing this in a file inside /etc/cron.d the cron needs an extra option, being the user to run your fancy/script.
# Minute Hour Day of Month Month Day of Week Who Command
# (0-59) (0-23) (1-31) (1-12 or Jan-Dec) (0-6 or Sun-Sat) root /my/fancy/script.sh
This is documented in man crontab(5). For example https://linux.die.net/man/5/crontab . It says:
Jobs in /etc/cron.d/
The jobs in cron.d are system jobs, which are used usually for more than one user. That's the reason why is name of the user needed. MAILTO on the first line is optional.
The sixth position is reserved for username running the job. You specified a user called sh which is most probably not present on the machine.
simple answer
on your crontab you need to specify the USER to run the command
example to run as ROOT is:-
0,10,20,30,40,50 * * * * root /path_to_script/script_name
or to run as user FRED
0,10,20,30,40,50 * * * * fred /path_to_script/script_name
default with no USER specified is to run as user CRON and that user would not have permissions to execute the script
We can create cron jobs for system as well for individuals. The crontab in /etc/crontab specifically used for system cronjobs. So you need to specify the cronjob command executed by whom. In the question the username not specified. Hence the ERROR (getpwnam() failed) occurs. You can create user specific cronjobs in /var/spool/cron/username
NOTE:: Cron jobs are very useful but disastrous on failures!
Nothing is wrong with the crontab file (so long as by "my" crontab, you mean that it's a user crontab rather than a system crontab; otherwise, see other answer).
On the other hand, something is wrong with your system's directory service -- as configured, in Linux, with nsswitch.conf. Perhaps you're using a Kerberos-authenticated LDAP store, and your cron daemon doesn't have a Kerberos token to connect to it (or is sandboxed, as with SELinux, not to have network access); perhaps it's a file store that isn't readable by the user whose crontab is being run; perhaps some other odd and interesting thing is going on.
getpwnam() is a C library call that performs a lookup for the name of the currently-logged-in user. If your shell were bash, it would fall back to a name of I have no name! -- so this error means your sh implementation is something different. (If you want to run your scripts with bash, use bash, not sh).

El Capitan: CRON Job is unable to trigger a shell script

*/10 * * * * /bin/sh /dataScience/dat/JOB/forker.sh
Above is the cron job which does not execute. I have checked separately both the functioning of cron job and shell script which works fine. Even the below command works well.
/bin/sh /dataScience/dat/JOB/forker.sh
I have also checked the permissions of forker.sh which shows
-rwxr-xr-x 1 mango wheel 442 Nov 20 12:53 forker.sh
Am i missing something which restricts the cron job from triggering the script?
Generally the syntax for the job goes like:
minute hour dom month dow user cmd
In your case, the job might be for multiple user, it seems
*/10 * * * * /bin/sh /dataScience/dat/JOB/forker.sh
Which implies it should be run at the interval of 10 mins all the time. Which is not problematic.
Can you tell us if the following is giving you the output at all?
*/10 * * * * (echo "Printing."; echo "Logging." > /dataScience/dat/JOB/abc.txt | mail -s "Mailing" your_email)
Note: I wanted to comment this, since this is not exactly the answer but debugging, but I have reputation lesser than 50, hence couldn't comment.

Laravel4 task to cron

I'm trying to create a cron using a task I made. The problem is I have no clue how to build the cron. My task name is meeting:close, and it's in my commands folder.
Can anyone help me to build the url to call this task every hour? I guess it will start with 0 * * * *
Thanks everyone!
To create a cronjob, you have to edit a file. It is pretty easy, run crontab -e to edit the cron file for the current user.
Now just add a line to the file that opens:
0 * * * * php /full/path/to/your/application/artisan meeting:close
Maybe you also have to specify the absolute path to your php executable
Now save the file and you're all set.
By the way, if you didn't know, you can run your commands with php artisan command:name from the terminal (that's also what the cronjob is going to do...)

CRON JOB is not running script

I'm trying to schedule a cron job here is my command:
*/5 * * * * USER -q /path/cron.php -mdefault 1
I'm trying to run this magento script every 5 minutes. I see the command being run when I open the cron log via grep CRON /var/log/syslog.
unfortunately the script never executes. I would appreciate any help.
Edit the crontab of the user you want to assign the job to:
sudo -u USER crontab -e
then in the crontab you can schedule the cron.php job in the following way:
*/5 * * * * php /path/to/cron.php

Resources