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

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.

Related

Cpanel CronJob several days of the week

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.

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.

running a script in crontab

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

RHEL 5.3: crontab runs multiple instances of script

I have a simple script that runs perfectly when used manually. When I entered into my crontab to run at 10 PM each night it appears to run several instances of the script, and times out my server. Any ideas?
22 * * * /mnt/myscript.sh
you are doing it wrong. It should've been
00 22 * * /mnt/myscript.sh.
Read about crons here.
https://access.redhat.com/site/documentation/en-US/Red_Hat_Enterprise_Linux/5/html/Deployment_Guide/ch-autotasks.html

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