Hi,
I have managed to cobble together the following script that moves files from one Samba share to another. It seems to work for all legal windows filenames except when there is a dollar character ($) in the filename. Typical filename it fails on is: ~$file.doc
Any help would be appreciated.
#!/bin/bash
# Script to move old files from public to quarantine
srcbase=/net/public
destbase=/net/quarantine
logfile=$srcbase/moved.log
date > $logfile 2>1&
find $srcbase -noleaf -atime +30 -print0 | while IFS="" read -r -d "" file ; do
if [ -f "$file" ]; then
relname="${file#*$srcbase}"
destname="$destbase$relname"
destdir="$(dirname "$destname")"
if [ ! -d "$destdir" ]; then
cmd1="mkdir -p \""$destdir"\""
eval "$cmd1" >> $logfile 2>&1
fi
cmd="mv --backup=t -v \""$file"\" \""$destname"\""
eval "$cmd" >> $logfile 2>&1
if [ -e "$destname" ]; then
cmd2="touch -a \""$destname"\""
eval "$cmd2" >> $logfile 2>&1
fi
fi
done
date >> $logfile 2>1&
echo Deleting empty directories from "$srcbase" >> $logfile 2>&1
find "$srcbase" -type d -empty -delete >> $logfile 2>&1