Cpanel CronJob several days of the week - cron

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.

Related

Check logfile size and alert if not updated in 30 minutes

I believe this is possible to do but not being an expert on Linux and shell scripting.
I believe I can use the watcher command to check the logfile directory but I am not sure how I would set it up to send an email alert to advise that this logfile directory hasn't been updated in 30 minutes.
Perhaps crontab would be of use to you:
Perform an action every minute:
echo "* * * * * touch $(pwd)/washere1" | crontab
Perform an action every 30 minutes:
echo "30 * * * * touch $(pwd)/washere2" | crontab
Check for the existence of the file "washere1" or "washere2" to verify that the command worked.

Cron run every minute ( Runs in bash but not in cron)

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.

Linux bash shell script output is different from cronjob vs manually running the script

I wrote a linux bash shell script which works fine except the output when I run it manually is different than when I run it from a cronjob.
The particular command is lftp:
lftp -e "lcd $outgoingpathlocal;mput -O $incomingpathremote *.CSV;exit" -u $FTPUSERNAME,$FTPPASSWORD $FTPSERVER >> ${SCRIPTLOGFILE} 2>&1
When I run the script manually, the ${SCRIPTLOGFILE} contains a lot of info such as how many files/bytes/etc transferred. But when I run the same script from a cronjob there is no output unless there was an error (such as could not connect). I have tried various terminal output configurations but none work for this lftp command. Suggestions?
It's worth reading this:
crontab PATH and USER
In particular, cron won't set the same environment variables you're used to an interactive shell.
You might want to wrap your entire cron job up in a script, and then you can, for example, temporarily add some code like export >> scriptenvironment.txt and see what the difference is between the cron invoked script and the interactively invoked script.
Try man 5 crontab for details.
Once you know what envrionment variables you need for your script to run, you can set them in the crontab as necessary, or source at the start of your own script.
EXAMPLE CRON FILE
# use /bin/sh to run commands, overriding the default set by cron
SHELL=/bin/sh
# mail any output to `paul', no matter whose crontab this is
MAILTO=paul
#
# run five minutes after midnight, every day
5 0 * * * $HOME/bin/daily.job >> $HOME/tmp/out 2>&1
# run at 2:15pm on the first of every month -- output mailed to paul
15 14 1 * * $HOME/bin/monthly
# run at 10 pm on weekdays, annoy Joe
0 22 * * 1-5 mail -s "It's 10pm" joe%Joe,%%Where are your kids?%
23 0-23/2 * * * echo "run 23 minutes after midn, 2am, 4am ..., everyday"
5 4 * * sun echo "run at 5 after 4 every sunday"

How to run cron job 1 hr after GMT 00:00 hr daily

I am new to ubuntu. I wants to run a cron job 1 hr after GMT 00:00 hr daily from my ubuntu machine.
I am using cron expression 00 01 * * *
So here are the steps which I performed but not success with this.
Step 1 : Open crontab with command crontab -e
Step 2 : make entry of cron expression as below
00 01 * * * /media/user1/Data/users/xyz/myjob.sh
But my script job.sh is not running with given expression.
Verify if the script is running standalone.
/media/user1/Data/users/xyz/myjob.sh
Also verify if the crontab entry is added by executing
crontab -l
add this to first line of your script
#!/bin/sh
and configure permissions
chmod +x /media/user1/Data/users/xyz/myjob.sh
on the terminal screen.
I hope it helps.

How to create a cronjob to backup crontab

Is there a way I can set a cronjob to backup the crontab on a daily basis?
The current way I'm going about this is as follows:
00 12 * * * crontab -l > ~/Documents/crontab_$(date +%Y%m%d).txt
but it's not working at all. Issuing this in the terminal as a non-cronjob task works fine.

Resources