Placement of shell script for cron to run

I have a shell script that I want cron to run as root. Where is the best to put the script? I put it in the root directory and pointed cron to run it but it cant find it.

Here is my cron settings 5 0 * * * mysqlbackup.sh as you can see it not pointing to the root directory. If I run a script from my home directory like this

5 0 * * * /home/mikemysqlbackup.sh it will run but i need root to run it.

Here is the shell script I created.

!/bin/bash

bash script to backup mysql

MYSQL_USER=root

MYSQL_PASSWORD=

MYSQLBACKUPDIR=/home/mike/mysql

BACKUP_LOG=/home/mike/mysql/backup.log

date +"%Y-%m-%d %X" > $BACKUP_LOG

backup musql databases

/usr/bin/mysqldump –user=$MYSQLUSER --password=$MYSQLPASSWORD --single-transaction --skip-lock-tables drupal6 | bzip2 -c > $MYSQLBACKUPDIR/drupal6-$(date -I).sql.bz2

date +"%Y-%m-%d %X" >> $BACKUP_LOG

send email

mailx -s "Micro: Backup Log" < $BACKUP_LOG

2 Replies

you can put it in root's home dir like so

/root/mysqlbackup.sh

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct