Results 1 to 2 of 2
I have a bash script, listed in crontab that archives my junk drawer.
THe problem is that for about half a dozen files it gave trying to mv saying
Code:
...
- 04-26-2009 #1Just Joined!
- Join Date
- Oct 2006
- Posts
- 3
Odd behavior with mv - "Directory not empty'
I have a bash script, listed in crontab that archives my junk drawer.
THe problem is that for about half a dozen files it gave trying to mv saying
If I copy the exact paths printed above (which are correct) and manually enterCode:mv: cannot move `/home/eddie/junk/logs' to `/home/eddie/junk/archive/2009_Feb/logs': Directory not empty
and it does as you would expect no trouble.Code:mv /home/eddie/junk/logs /home/eddie/junk/archive/2009_Feb/logs
So why is it different in my script? The obvious different is the IFS, but I am doing this to allow files with spaces, and it works fine if the destination directory doesn't exist.
Code:#!/bin/bash #change IFS so we can handle files with spaces RETURNIFS=$IFS #IN case we blow, trap for exit so we can restore IFS trap `IFS=$RETURNIFS` 0 1 2 6 9 # copy in place, trap set, change IFS IFS=$(echo -en "\v") OLDFILES=$ACTIVE_DIR/* set -- $OLDFILES # run thoughm, compare time and move out or in. for ITEM in $OLDFILES do mv $ITEM $DPATH if [ $? -ne 0 ] then echo "Error while moving last file" | tee -a $LOGFILE exit 2 else printf "\tSuccess\n" | tee -a $LOGFILE fi fi done IFS=$RETURNIFS
- 04-28-2009 #2Just Joined!
- Join Date
- Apr 2009
- Posts
- 90
If you are 100% sure that the folder you want to move to doesn't exist,
then add a rm -fr before the mv command?


Reply With Quote