質問

I'm running a combination backup script from a root cron on my Ubuntu 10.04 LTS Server.

The root cron looks like this:

# m h  dom mon dow   command
0 1 * * 2-6 /home/cbhiadmin/archive

It's executed as it's expected. The archive command kicks off several individual facility backups. The code is as follows:

#!/bin/bash

# This script executes several individual facility archive processes & logs success.

/home/cbhiadmin/archive104
/home/cbhiadmin/archive106

if [ $? -ne 0 ]; then
  echo "$(date '+%m/%d/%y-%H:%M') Nightly Addon backup SUCCESSFUL" >> /home/cbhiadmin/addon_backups/addon_backup.log
  exit
  fi

Then the last part is an individual facility backup as follows:

#!/bin/bash

# This script archives a facility, FTPs the archive to 10.5.2.76, & logs failure.

today=$(date '+%m%d%y')
site="106"

cd /home/cbhiadmin/addon_backups/"$site"

if [ ! -f "$site"adata_"$today".tar.gz ]; then

tar --exclude *.CSV --exclude *.csv -czf "$site"adata_"$today".tar.gz -C /usr/bbx/aon/ "$site"/ADATA/

  if [ $? -ne 0 ];then
  echo "$(date '+%m/%d/%y-%H:%M') $site: Nightly Addon backup FAILED" >> /home/cbhiadmin/addon_backups/addon_backup.log
  fi

fi

cp "$site"adata_"$today".tar.gz /home/cbhiadmin/SAN/"$site"

find ~/SAN/"$site"/*.tar.gz -maxdepth 1 -mtime +60 -exec rm {} +

My problem is that the last line does not seem to work from the root cron, but works when I run the archive as root myself.

What's missing?

役に立ちましたか?

解決

find ~/SAN/"$site"/*.tar.gz -maxdepth 1 -mtime +60 -exec rm {} +

"~" refers to the user's home directory. However, when run by cron, it is not using your user and therefore, you home directory. Change it to refer to an absolute path.

他のヒント

Please follow the below steps and It should fix your problem :

  1. type cd ~/SAN/
  2. type pwd
  3. replace "~/SAN/" with the results from the pwd command.
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top