Pull my hair out
I have created a bash script to look at backup counts if it exceeds two to delete oldest one. However I keep getting an error "cp: cannot stat `backup1.log': No such file or directory". The directory is valid and root has read, write / user has read, write / others have not permission to the file. I have created another script and it work fine. This new script doesn't..... Below is the new script
backup_dir=/var/CPbackup/backups log=/root/bin/backup.log backup_count=`ls|grep ^backup|wc -l` file_to_delete=`ls|grep ^backup|head -1` file_to_copy=`ls|grep ^backup` if [[ ${backup_count} > 2 ]] then ${file_to_delete} echo "`date`: Deleting ${file_to_delete}" >> ${log} rm -f ${file_to_delete} echo "`date`: File has been deleted." >> ${log} else echo "`date`: Mounting cifs Mirror..." >> ${log} mount -t cifs //10.172.0.223/Mirror$ /mnt/offsite -o credentials=/root/bin/.tarconnect cd ${backup_dir} echo "`date`: Copying file_to_copy to WF13WP03..." >> ${log} cp ${file_to_copy} /mnt/offsite/Offsite\ Mirror/ >> ${log} echo "`date`: Copy complete unmount cifs from WF13WP08..." >> ${log} umount /mnt/offsite fi |
Are you running the script as root?
|
@Ihatewindows522
Yes I am running the script as root |
Quote:
|
Is the posted script complete?
Is the new one and the posted one identical? As stated the script will assign variables file_to_delete, file_to_copy and backup_count based upon the current working directory versus the backup directory. |
1. See http://www.tldp.org/LDP/abs/html/comparison-ops.html
Code:
if [[ ${backup_count} > 2 ]] 2. Try adding Code:
set -xv |
No solution for you, but you might want to change the ``'s to $(). It's easier to read and does the same thing. And for some things the difference between success and failure.
$ echo `date` $ echo $(date) |
All times are GMT -5. The time now is 11:16 PM. |