2

Hi All Ubuntu Server Experts

I need help in cracking this crontab problem. So, I made a change in /etc/crontab to run a system script for database backup purpose. The crontab does not seems to run my script and I cannot view the crontab status anywhere. I even uses root account for my ubuntu server.

So, I made a simple echo script in crontab and it worked ok. What is wrong with my script?

Here are some clues: This is my /etc/crontab file

# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/DataBank/Bac$

# m h dom mon dow user  command
17 *    * * *   root    cd / && run-parts --report /etc/cron.hourly
25 6    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --repo$
47 6    * * 7   root    test -x /usr/sbin/anacron || ( cd / && run-parts --repo$
52 6    1 * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --repo$
*  *    * * *   root    sh /DataBank/Backup/Scripts/backupdb.sh --> this one does not run
*  *    * * *   root    echo "Running Sample Crontab by the minute: $(date)" >>$ --> this one works

and This is my backup scripts located at /DataBank/Backup/Scripts/backupdb.sh:

echo "Backing up database... $(date)" >> backuplog.txt
DBFILENAME=db`date "+%Y%m%d-%H.%M.%S"`.sql
/Tech/MySQL/Server/bin/mysqldump -c ITWorksEEDB > ../DB/$DBFILENAME --user=root$
echo "Backup done: $DBFILENAME $(date)" >> backuplog.txt

and My backup file permissions: (all 777)

root@MoMa:/DataBank/Backup/Scripts# ls -al
total 11
drwxrwxrwx 1 root root 4096 Jan  4 13:03 .
drwxrwxrwx 1 root root 4096 Oct  8 21:13 ..
-rwxrwxrwx 1 root root  257 Jan  4 13:05 backupdb.sh
-rwxrwxrwx 1 root root  257 Jan  4 13:32 backupdb.sh.bak
-rwxrwxrwx 1 root root  236 Jan  4 13:05 backuplog.txt
-rwxrwxrwx 1 root root   79 Jun 25  2013 shutAll.sh
-rwxrwxrwx 1 root root   55 Aug 23  2012 shutSPC.sh

When I run the backupdb.sh manually using "sh backupdb.sh", it works perfectly. When I use this command: ./backupdb.sh (without sh), this error message occurs:

root@MoMa:/DataBank/Backup/Scripts# ./backupdb.sh
-bash: ./backupdb.sh: Permission denied --> My backupdb.sh file is supposed to be 777

Can anyone help me how to make the script run in crontab or at least to see the status returned by crontab when running the script?

Thank you Rendra

  • Two things, 1) never edit crontab manually, always use crontab -e from the specific user account. 2) cron has no environment, i.e. just because a command in on your PATH does not mean that it will be on cron's. – Boris the Spider Jan 4 '16 at 10:22
1

I am going to answer my own question... It is simple actually after trial and error... the script to be set in crontab MUST contain FULL PATH, not relative path.

I hope my experience can help anyone out there since crontab does not provide any analysis of what happened when a script does not run.

  • Crontab emails the user running the command with the output in case of error. – Boris the Spider Jan 4 '16 at 10:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.