Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Crontab does not run on CentOS 7

I'm using CentOS 7, and installed "cronie"

yum install cronie

I have a shell to backup my home folder, shell's content (of course, backup.sh is 775)

#!/bin/bash
#START
TIME=`date +%Y-%m-%d_%Hh%M`          
FILENAME=backupHome_123.30.150.29_$TIME.tar.gz 
SRCDIR=/home                    
DESDIR=/backup            
tar -cpvzf $DESDIR/$FILENAME $SRCDIR
#END

And add to crontab -e

00 2 * * * /bin/bash /backup/backup.sh

But crontab does nothing. When I check log at /var/log/cron only, something like that and no more error or processing log

May  1 00:26:08 app crontab[12041]: (root) END EDIT (root)
May  1 00:33:21 app crontab[12086]: (root) BEGIN EDIT (root)
May  1 00:34:25 app crontab[12086]: (root) END EDIT (root)

Anyone can give me some advises to make crontab work? Thank you.

like image 971
thienhaxanh2405 Avatar asked Dec 04 '22 00:12

thienhaxanh2405


2 Answers

I found that the most useful information was actually given by

systemctl status crond

Which revealed that it failed to load correctly due to an "Unauthorized SELinux context" error.

like image 54
Nagev Avatar answered Dec 17 '22 22:12

Nagev


This can happen if cron daemon isn't running. Check it with:

pgrep cron

If command returns nothing, run:

systemctl restart crond

This should help.

like image 38
dtrizna Avatar answered Dec 17 '22 23:12

dtrizna