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: ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 04-26-2009 #1
- Join Date
- Oct 2006
Odd behavior with mv - "Directory not empty'
THe problem is that for about half a dozen files it gave trying to mv saying
mv: cannot move `/home/eddie/junk/logs' to `/home/eddie/junk/archive/2009_Feb/logs': Directory not empty
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.
#!/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 #2
- Join Date
- Apr 2009
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?