Cronjob permission denied (Nightly backup shell script)
I am trying to create a shell script to make a backup every night using tar.
The error I get is:
From shady@wserver1 Wed Dec 30 04:01:01 2015
Return-Path: <shady@wserver1>
X-Original-To: shady
Delivered-To: shady@wserver1
Received: by wserver1 (Postfix, from userid 1000) id 23DBE15620F5; Wed, 30 Dec 2015 04:01:01 -0500 (EST)
From: root@wserver1 (Cron Daemon)
To: shady@wserver1
Subject: Cron <shady@wserver1> /home/shady /backup.sh
Content-Type: text/plain; charset=ANSI_X3.4-1968
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/home/shady>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=shady>
Message-Id: <20151230090101.23DBE15620F5@wserver1>
Date: Wed, 30 Dec 2015 04:01:01 -0500 (EST)
/bin/sh: 1: /home/shady: Permission deniedThe script looks like this:
#!/bin/sh
####################################
#
# Backup to NFS mount script.
#
####################################
# What to backup.
backup_files="/home /var/www /var/lib/mysql"
# Where to backup to.
dest="/media/backups"
# Create archive filename.
date=$(date +"%m_%d_%Y_%H_%M_%S")
hostname=$(hostname -s)
archive_file="$hostname-$date.tgz"
# Print start status message.
echo "Backing up $backup_files to $dest/$archive_file"
date
echo
# Backup the files using tar.
tar czf $dest/$archive_file $backup_files
# Print end status message.
echo
echo "Backup finished"
date
# Long listing of files in $dest to check file sizes.
ls -lh $destIt works fine if I run the command using sudo su, but I can't do that with a cron job. The permissions are very strict for /var/lib/mysql, but I could always back that up manually if it comes to that. However, /home and /var/www are both set to 775 and it's still not working. Any help?
1 Answer
shady user doesn't have permission to execute backup.sh file for auto cron job
try to run it fist manually with shady user also set permission for backup.sh
chmod +x backup.sh