I have to start a cronjob on every Thursday. Here is the script.
It will not start at all.
Manually it does his work but not as a cronjob.
It should start at 17.00 every Thursday:
00 17 * * 4 root cd /var/www/domein.nl/admin/scripts && php -f send_newsletter_subscribers.php
also tried to do as text: wed
33 15 * * wed root cd /var/www/domein.nl/admin/scripts && php -f send_newsletter_subscribers.php
Have no idea why it doesn't work.
Does anybody have any suggestion what I'm doing wrong?
Thanks in advance for replying.
Is this an individual user's crontab (edited with crontab -e) or a system level crontab file? If the former, then the syntax is wrong, and you need to remove the user specification ("root").
The time and date fields look fine.
Think about setting some important variables in your /etc/initab (specially PATH and SHELL).
My /etc/initab file contains the following:
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/root
Related
I am new to cron jobs, and I want to run a script on several days of the week
I did create a CronJob but it didn't run last night.
I want to execute the script every night at 00:10 on Sunday through thursday
So I added this as the Job
10 00 * * 0,1,2,3,4 execute.php
Can somebody tell me what I'm doing wrong?
Set it to run daily and just add this to the top of your script
if (date('l') == 'Friday' || date('l') == 'Saturday') exit;
That way it won't even do anything unless it's a day you require and saves you a headache.
root user on shell (WHM/Cpanel over Centos)
# crontab -e #Edit cron jobs for user root
10 00 * * 0,1,2,3,4 /usr/local/cpanel/3rdparty/bin/php /full/path/to/execute.php >/dev/null 2>&1 #If not like report to email
user cpanel
with shell acces
$ crontab -e #Edit cron jobs for user
10 00 * * 0,1,2,3,4 /usr/local/cpanel/3rdparty/bin/php /full/path/to/execute.php >/dev/null 2>&1 #If not like report to email
or
10 00 * * 0,1,2,3,4 /usr/bin/php /full/path/to/execute.php >/dev/null 2>&1 #If not like report to email
without shell access
Enter Cpanel and go to Cronjobs.
Put your tiem on each text input area.
Put your job 10 00 * * 0,1,2,3,4 /usr/local/cpanel/3rdparty/bin/php /full/path/to/execute.php >/dev/null 2>&1 #If not like report to email
Explanations
/usr/local/cpanel/3rdparty/bin/php PHP compiled for WHM/Cpanel functions.
/usr/bin/php PHP used by normal Cpanel installation
It's possible other paths if your server used for example, Couldlinux with multiples PHP versions.
This have been discussed several times in previous post. I followed given advise but it does not work for me. I have two scripts which are run by the cron service every minute. To my surprise, only one runs per minute( 1st in the list below), the other fails (2nd in list below). Most surprising, when run direct from the terminal, both scripts execute fine.
Cron setup :
*/1 * * * * /home/user/Desktop/scripts/generatepattern.sh
*/1 * * * * /home/user/Desktop/scripts/getnextfile.sh
File permissions are:
-rwxr--r-- 1 user user 522 Jul 25 16:18 generatepattern.sh
-rwxr--r-- 1 user user 312 Jul 25 23:02 getnextfile.sh
The code for the non-schedulable( not running in cron ) is :
#!/bin/bash
#Generate a file to be used for the search
cd /home/user/Desktop/scripts
no=`cat filecount.txt`
if test $no -lt 20
then
#echo "echo less"
#echo $no
expr `cat filecount.txt` + 1 >filecount.txt
fi
In the last line you wrote cat filecount.txt instead of cat /home/user/Desktop/scripts/filecount.txt
I discovered the main issue was that the new cron settings only get used when the vi editor gets closed. Changes have to be made on the editor and a :wq command issued so that the new settings get installed. Just issuing :w command does not work since no install happens(this was my mistake). I realised this after issuing :wq command on vi and the following output displayed :-
# crontab -e
crontab: installing new crontab
Thanks to all other suggestions made.
I have a very simple script in my crontab that I want to run every day. It is located in /home:
-rwxr-xr-x 1 root root 40 Apr 15 08:01 kill_slony_stop_sql.sh
It has execute permission and here is the content:
#!/bin/bash
slon_kill;rcpostgresql stop
and here is the cron line for it to run daily:
56 12 * * * /home/kill_slony_stop_sql.sh
But it is not working for some reason. When I type /home/kill_slony_stop_sql.sh in the command line, it works good but it is not working in the crontab.
Any thoughts?
It is most likely a PATH issue. Have a look at Why is my crontab not running and be sure to set a PATH so that it can call your slon_kill command.
Also, add some debug to your cron
56 12 * * * /home/kill_slony_stop_sql.sh &>/tmp/errorcron.log
And also look at the logs; cron logs its actions via syslog, which (depending on your setup) often go to /var/log/cron or /var/log/syslog.
I had the same problem with a daily cron job, I used the #daily but this will run at 00:00 every day.
#daily /usr/local/bin/msa70_check.sh
was the cron tab line i added, below is the script i run.
#!/bin/bash
# msa70 disk check
/sbin/mdadm --detail /dev/md0 /dev/md1|
/bin/mailx -s"Disk check on server123 please check" person#domain.com
I also had to edit my script and add /sbin/ and /bin in front of mdadm and mailx for the cron job to run
I define a job with crontab like this
0 2 * * * dbadmin . /home/dbadmin/back.sh
it is not root I want to run this .sh file with dbadmin user.
but when I checked it is not working.
in the log it gives this:
Feb 22 21:16:01 localhost crond[14634]: (*system*) BAD FILE MODE (/etc/crontab)
Feb 22 21:16:01 localhost crond[14634]: (dbadmin) RELOAD (cron/dbadmin)
Feb 22 21:16:01 localhost crond[28451]: (dbadmin) CMD (dbadmin . /home/dbadmin/back.sh)
How can I fix this? thanks in advance
Make a crontab entry as dbadmin without the username in it:
0 2 * * * /home/dbadmin/movefolder.sh > /home/dbadmin/cron.out 2>#1
Each day the logfile /home/dbadmin/cron.out should be replaced by a new one.
When you are confident about the cron+movefolder, replace the outputfile with /dev/null.
When above fails, check calling the script as dbadmin:
sh /home/dbadmin/movefolder.sh
When this one works and cron fails, it might be the environment. Try saomething like
0 2 * * * . /home/dbadmin/.profile; /home/dbadmin/movefolder.sh > /home/dbadmin/cron.out 2>#1
Using the crontab program, you normally have access only to the 5 scheduling fields (minute, hour, day of month, month and day of week). However, with Vixie cron (usually on Linux) by editing the system crontab file (/etc/crontab, as well as files in /etc/cron.d) you can use the 6th field for the username. For example, see How to specify in crontab by what user to run script?
If you use crontab to enter this line
0 2 * * * dbadmin . /home/dbadmin/back.sh
^^^^^^^
the "dbadmin" username is treated as the command to execute. You can (as noted in crontab's manual page) use that line in /etc/crontab. I pointed out that this is Vixie (also known as ISC) crontab. Legacy systems such as Solaris have a less capable crontab which would not allow specifying the user to run under.
According to cron's manual page, it will send output via email. Perhaps there was no email because the command "dbadmin" failed.
You need to use sh command for executing sh file.like following
0 2 * * * dbadmin sh /home/dbadmin/movefolder.sh
Hope it works.
Thank you.
I'm having no idea why my cronjob isn't executed. Here are the details:
I've a script inside /usr/src named stundenplan.sh, which executes a jar file.
The script itself works if you are running it from the console.
But trying to run it from a cronjob it doesn't work.
The script looks like this:
#!/bin/sh
java -jar vorlesungsplaene.jar
The jar file lies in the same directory as expected.
I defined two cronjobs:
# m h dom mon dow command
30 * * * * /usr/src/stundenplan.sh
0-59 * * * * echo "dude" >> /tmp/test.txt
The job below works fine, writing "dude" meticulously in the test.txt file.
As you can see in the syslog, the job above fails:
Jul 18 15:29:01 vps47327 /USR/SBIN/CRON[16361]: (root) CMD (echo "dude" >> /tmp/test.txt)
Jul 18 15:30:01 vps47327 /USR/SBIN/CRON[16364]: (root) CMD (/usr/src/stundenplan.sh)
Jul 18 15:30:01 vps47327 /USR/SBIN/CRON[16365]: (root) CMD (echo "dude" >> /tmp/test.txt)
Jul 18 15:30:01 vps47327 /USR/SBIN/CRON[16363]: (CRON) error (grandchild #16364 failed with exit status 1)
Any suggestions, ideas or solutions? ;)
It looks like a path issue. Crontab is probably being run from some arbitrary directory so it can't find the jar file.
Try doing:
30 * * * * cd /usr/src && ./stundenplan.sh
That's not really the prettiest way to go about it, but if it works, then at least you know what the problem is. Possibly it might be more elegant to put the full path of the jar file in the script then, but I'll leave that question to you. :)
Hope it helps!