mv inside ksh script problem
folks;
I have a script to remove any files that older than 14 days then move any files that younger than 7 days to another directory. but for some reason it doesn't move the files, when i do it manually it works fine and find but not through the script. i tried 2 different ways in writing the move part but it didn't work with any of them. Any help is greatly appreciated here it's: cd /var/lib/mysql files=$(find . \( -name 'mysql-bin.0*' \) -mtime +14 -print | sed 's+^\./++;s+/.*++' | sort -u) if [ -z "${files}" ]; then echo "" echo "-------------------No SQL backup files to be removedi from the var directory -------------------------" else echo "" echo "" echo "...........Removing old files...................." rm -rf ${files} echo "" echo "" file=$(find . \( -name 'mysql-bin.0*' \) -mtime -7 -print | sed 's+^\./++;s+/.*++' | sort -u) #mv `find . \( -name 'mysql-bin.0*' \) -mtime -7 -print | sed 's+^\./++;s+/.*++' | sort -u` /var/lib/mysql/backups/ mv ${file} /var/lib/mysql/backups/ sleep 1 fi |
The quick way to debug it is to use
set -xv at the top of the script and run it again. It'll show you exactly whats going on, inc values for all variables |
here's what i see:
cd /var/lib/mysql ++ cd /var/lib/mysql files=$(find . \( -name 'mysql-bin.0*' \) -mtime +14 -print | sed 's+^\./++;s+/.*++' | sort -u) find . \( -name 'mysql-bin.0*' \) -mtime +14 -print | sed 's+^\./++;s+/.*++' | sort -u +++ find . '(' -name 'mysql-bin.0*' ')' -mtime +14 -print +++ sed 's+^\./++;s+/.*++' +++ sort -u ++ files= if [ -z "${files}" ]; then echo "" echo "-------------------No SQL backup files to be removedi from the var directory -------------------------" else echo "" echo "" echo "...........Removing old files...................." rm -rf ${files} echo "" echo "" file=$(find . \( -name 'mysql-bin.0*' \) -mtime -7 -print | sed 's+^\./++;s+/.*++' | sort -u) #mv `find . \( -name 'mysql-bin.0*' \) -mtime -7 -print | sed 's+^\./++;s+/.*++' | sort -u` "/var/lib/backups/" mv ${file} /var/lib/backups/ sleep 1 fi |
All times are GMT -5. The time now is 06:24 AM. |