Cron job

Hi,
I’m more or less new to linux and opensuse. I want to make a regular backup of my mysql db. Therefore I wrote a script which looks like this: (the script itself works fine)

#!/bin/sh

DATE=date '+%Y-%m-%d_%H:%M:%S-%Z'
DBNAME=“proteios”
DBUSER=“proteios”
DBPASS="***"
DIRECTORY_OUTPUT="/data/backup/proteios/db"

mysqldump -u $DBUSER --password=$DBPASS -B $DBNAME > $DIRECTORY_OUTPUT/$DBNAME.$DATE.sql

I moved it to /etc/cron.daily. Unfortunately this script isn’t executed daily. I thought the crontab checks every 15min the directories cron.daily, cron.hourly… whether there are scripts to execute.

Has anyone a hint for me what’s wrong?
(my system is suse 11.1)

did you make the file executable?

Hi
By default cron doesn’t know about paths to files, therefore you either
need to add a PATH statement in your script/cron job. The easiest is to
provide the full path to mysqldump, date etc eg: /bin/date


Cheers Malcolm °¿° (Linux Counter #276890)
SUSE Linux Enterprise Desktop 11 (x86_64) Kernel 2.6.27.42-0.1-default
up 18 days 12:17, 4 users, load average: 1.15, 0.34, 0.13
GPU GeForce 8600 GTS Silent - CUDA Driver Version: 190.53

Yes the script is executable (I’ve tested the script via the console and everything worked fine)
I’ve added the full path. Let’s see if that works. (I’ll tell you tomorrow)

More correctly, cron jobs have a very basic PATH, usually the hardwired default of the shell. I did an echo $PATH in a cron job and it returned:

/usr/bin:/bin

But that PATH should have date and mysqldump. Still, any command not in the PATH should use the absolute path, or one should set PATH at the top of the script.

A couple of tips: You can see if the job was attempted by grep cron /var/log/messages. And you should send the output of the cron job somewhere where it can be logged. At the top of the script you can put

exec > /var/log/mysqlbackup.log 2>&1

to divert all output to the log file.

Another reason might be the script needs to be owned by root, a security measure.

Ah thanks for all the information.