How do I delete folders in bash after successful copy (Mac OSX)?
- by cohortq
Hello! I recently created my first bash script, and I am having problems perfecting it's operation. I am trying to copy certain folders from one local drive, to a network drive. I am having the problem of deleting folders once they are copied over, well and also really verifying that they were copied over). Is there a better way to try to delete folders after rsync is done copying? I was trying to exclude the live tv buffer folder, but really, I can blow it away without consequence if need be. Any help would be great! thanks!
#!/bin/bash
network="CBS"
useracct="tvcapture"
thedate=$(date "+%m%d%Y")
folderToBeMoved="/users/$useracct/Documents"
newfoldername="/Volumes/Media/TV/$network/$thedate"
ECHO "Network is $network"
ECHO "date is $thedate"
ECHO "source is $folderToBeMoved"
ECHO "dest is $newfoldername"
mkdir $newfoldername
rsync -av $folderToBeMoved/"EyeTV Archive"/*.eyetv $newfoldername --exclude="Live TV Buffer.eyetv"
# this fails when there is more than one *.eyetv folder
if [ -d $newfoldername/*.eyetv ];
then
#this deletes the contents of the directories
find $folderToBeMoved/"EyeTV Archive"/*.eyetv \( ! -path $folderToBeMoved/"EyeTV Archive"/"Live TV Buffer.eyetv" \) -delete
#remove empty directory
find $folderToBeMoved/"EyeTV Archive"/*.eyetv -type d -exec rmdir {} \;
fi