Originally Posted by
cortman
...
Code:
if [ -d /home/cortman/data/backup ] ;
then
mv /home/cortman/data/backup backup.old ;
mkdir /home/cortman/data/backup ;
cp /home/cortman/doug /home/cortman/data/backup ;
else
mkdir /home/cortman/data/backup ;
cp /home/cortman/doug /home/cortman/data/backup ; fi
The problem:
...
I run it a fourth time, and get an error
Code:
mv: cannot move `/home/cortman/data/backup' to `backup.old/backup': Directory not empty
mkdir: cannot create directory `/home/cortman/data/backup': File exists
One thing that might create an error is that you have a relative path in the move-target. This would be better:
Code:
mv /home/cortman/data/backup /home/cortman/backup.old
but maybe your main problem is that you should delete the old directory before the move command. So maybe this script would work
Code:
#! /bin/bash
if [ -d /home/cortman/data/backup ]
then
rm /home/cortman/backup.old
mv /home/cortman/data/backup /home/cortman/backup.old
mkdir /home/cortman/data/backup
cp /home/cortman/doug /home/cortman/data/backup
else
mkdir /home/cortman/data/backup
cp /home/cortman/doug /home/cortman/data/backup
fi
By the way, rsync is a more powerful alternative than cp for this kind of task. Read
Bookmarks