通过sshfs 挂载远程主机文件夹到本地,脚本监测最新更新的图片文件。
复制到挂载的文件夹下,复制之前先检测sshfs是否运行,如果不存在进程则启动。
#!/bin/bash
#find . -type f -mtime -7 | while read f
dd=`ps cax | grep sshfs | grep -o '^[ ]*[0-9]*'`
if [ ! ${dd} ];then
sshfs -o allow_other root@67.198.146.226:/www/web/intosmile.com/frontend/web/media/catalog/product /intosmile/www/web/onfancy.com/media/catalog/product
fi
find /www/web/onfancy.com/media/catalog/product -path '/www/web/onfancy.com/media/catalog/product/cache' -prune -o -type f -mmin -3 | while read f
do
#echo ${f##*/}
dd=`ps cax | grep sshfs | grep -o '^[ ]*[0-9]*'`
if [ ! ${dd} ];then
sshfs -o allow_other root@67.198.146.226:/www/web/intosmile.com/frontend/web/media/catalog/product /intosmile/www/web/onfancy.com/media/catalog/product
fi
if [ ${f##*/} != "cache" ];then
echo ${f};
#filedir=`expr substr "$f" 2 ${#f}`
filedir=${f}
oldfiledir=${filedir}
newfiledir='/intosmile'${filedir}
echo ${oldfiledir}' was copy to '${newfiledir}
mkdir -p -- "$(dirname -- "$newfiledir")" && cp -Rrf "$oldfiledir" "$newfiledir" ;
fi
done
~