How to create a cronjob to backup crontab - cron

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.

Related

Created cron job to run every 2 mint

I have configured cron job but it's not working.
I wanted to run the myfile.sh script for every 2 mint and below are my configuration in crontab.
# m h dom mon dow comman
2 * * * * /home/ubuntu/myfile.sh
myfile.sh is executable and contains below lines of code
#!/bin/bash
mysqldump -u[user] -p[password] --single-transaction --routines --triggers --all-databases > /home/ubuntu/backup_db10.sql
Is there anywhere we need to add configure anything?
You're running the script at two minutes past every hour. As in 1:02, 2:02 and so on.
You can change it to something like
*/2 * * * * /home/ubuntu/myfile.sh
to run it every two minutes.
A bit more info can be found here.

Cron job not running automatically for a non-root user

I am running SUSE Linux as a non-root user (getting root access also will not be a possibility). I would like to have a .sh script I created be run daily.
My crontab looks like:
0 0 * * * * /path/to/file.sh
I also have a line return after this as per many troubleshooting suggestions. My script deletes files older than 14 days. I also added a means to log output to check whether the script runs.
However, the job does not run automatically. I also am not able to check /var/log/messages for any notifications on whether cron can run or not.
What am I doing wrong? How can I check if cron itself is running/can run for my user? Do I have to supply cron with any paths or environment variables?
The correct approach to run your cron every midnight is:
00 00 * * * /bin/bash path/to/your/script.sh >> /path/to/log/file.log

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.

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.

Using Cron to Reboot

I'm using a Raspberry Pi for a status display, but for whatever reason it gets incredabbly sluggish after a day or so of running so I wanted to reboot it every day so I setup a cron job to do that every morning at 8:50. But, it doesn't seem to be working. Is there anything special about using cron to do a reboot?
This is my crontab for the root user:
# m h dom mon dow command
50 8 * * * shutdown now -r >> /var/log/cron.log
0,30 * * * * date >> /var/log/cron.log
The second line works just fine, but I can't seem to get the restart command to work. It doesn't even output anything to the log.
Try using the fully specified path to shutdown. date may be in the PATH in roots cron environment, /sbin may not be looked up.
You need to edit the root user crontab
sudo crontab -e
then..
50 8 * * * reboot
Save and exit.

Resources