CRON JOB is not running script - magento

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

Related

How do I activate cron job?

I edited the cron file on my Mac running catalina.
I used this code:
crontab -e
And then I added this line
* * * * * python3 ~/Documents/Scripts/script.py
My expectation is that it should run every minute but it hasn't run once.
Do i need to do something special to activate cron on this machine?
Updated my code based on the conversation in the comments to this
* * * * * /usr/local/bin/python3 ~/Documents/Scripts/script.py >>~/Documents/Scripts/script.log 2>&1

How to schedule sqoop job using crontab

I have created sqoop job which is working perfectly but when I am trying to schedule it using crontab it is not working.I have scheduled it as follows,
50 12 * * * sqoop job --exec myjob_direct_append >> /home/training/my_Local/direct_append1.log
Please Guide the correct way to do it.
This looks fine to me. Where are you executing this from? Is it a system crontab (usually /etc/crontab) ?
Try scheduling:
* * * * * sqoop job --exec myjob_direct_append >> /home/training/my_Local/direct_append1.log 2>&1
This would run every minute and log any error message to the direct_append1.log so you can debug the issue quickly.

How to execute a script using crontab

I'm trying to execute a particular script located in /logann/myFile through crontab file.
I've already tried a lot of ways but no one makes any results.
I add in crontab file this line to call my script
26 10 * * * root cd /logann && ./apagar_temp_tomcat
(The time I change to test)
And my script is
#!/bin/sh
rm /tmp/tomcat7-tomcat7-tmp/*.tmp
rm /tmp/tomcat7-tomcat7-tmp/*.xml
I just want to execute this script. This script will delete every .tmp/.xml files in the folder tomcat7-tomcat7-tmp.
Any ideas?
Thank you guys!
cron jobs will run in their own shell. So you can't expect to see tedvs on your console.
Try to write something in file, for example
* * * * * echo tedvs > file_in_your_directory.txt
Just make one function in file and call that file or function in cron as per your time interval.
I did this in PHP
shell_exec(\'(crontab -l ; echo "* * * * * curl www-data http://localhost/sp/delete.php") | crontab -\');

Output not going to file when ran as a cron job

I have the following bash script:
clean-tmp.sh
#!/bin/bash
tmpreaper 1h /tmp --test > ./tmpreaper.log
When I run it in the terminal using ./clean-tmp.sh, it writes to the file ./tmpreaper.log.
I added the script to the list of cron jobs using crontab -e:
*/5 * * * * cd /home/cron-jobs && ./clean-tmp.sh
I then checked cron's logs and this entry is in there every 5 minutes:
Feb 19 00:45:01 ip-172-31-23-184 CRON[1475]: (ubuntu) CMD (cd /home/cron-jobs && ./clean-tmp.sh)
But it's no longer writing to ./tmpreaper.log.
What on earth am I doing wrong?
Just specify an absolute path for your file, like tmpreaper 1h /tmp --test > /var/log/tmpreaper.log
#Kacy: Little difficult to say without cron logs, you could have a look to cron logs(/var/log/cron etc).
0,5,10,15,20,25,30,35,40,45,50,55 * * * * cd /home/cron-jobs; ./clean-tmp.sh
May be some systems wouldn't allow time period as the way you tried, try once in above way and let us know then.

"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).

Resources