How do I delete folders in bash after successful copy (Mac OSX)?

Posted by cohortq on Stack Overflow See other posts from Stack Overflow or by cohortq
Published on 2010-03-22T21:39:27Z Indexed on 2010/03/22 21:41 UTC
Read the original article Hit count: 201

Filed under:
|
|
|

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

© Stack Overflow or respective owner

Related posts about bash

Related posts about macosx