我最近创建了我的第一个 bash 脚本,但在完善它的操作时遇到了问题。我正在尝试将某些文件夹从一个本地驱动器复制到网络驱动器。
我在复制文件夹后遇到删除文件夹的问题,有时文件夹中没有内容,但文件夹本身会保留,有时什么也不会发生。rsync 完成复制后,有没有更好的方法来尝试删除文件夹?我试图排除直播电视缓冲区文件夹,但实际上,如果需要,我可以将它吹走而不会产生任何后果。
#!/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