# Path to yetishare files directory
Path="/drive2/us1/files/"
# SQL info
Host=
DBname=
Username=
Pass=
# remove to remove files or list to list files
Action=remove
#=====================================
if [ $Action == list ]
then
FILES=$(find $Path -maxdepth 2 -type f | grep -v -e "htaccess" -e "_deleted" -e "_tmp" | sed "s:$Path::g")
for f in $FILES
do
Result=$(mysql -h $Host -u $Username -p$Pass $DBname -e "SELECT localFilePath, shortUrl FROM file WHERE localFilePath = '$f'")
if [ -z "$Result" ]
then
echo "$f"
fi
done
elif [ $Action == remove ]
then
FILES=$(find $Path -maxdepth 2 -type f | grep -v -e "htaccess" -e "_deleted" -e "_tmp" | sed "s:$Path::g")
for f in $FILES
do
Result=$(mysql -h $Host -u $Username -p$Pass $DBname -e "SELECT localFilePath, shortUrl FROM file WHERE localFilePath = '$f'")
if [ -z "$Result" ]
then
echo "Removing $f"
rm -f $Path$f
fi
done
else
echo "It seems like there is a problem with configuration, Action should be either list of remove but it's set to be $Action"
fi