SELL脚本工具:linux下监听scp传输文件,传输成功后打印新上传文件名

孤者浪人 提交于 2020-01-07 00:21:51

【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>>

#! /usr/bin/expect
#!/bin/bash  
PROC_NAME="scp" 
ProcNumber=`ps -ef |grep $PROC_NAME|grep -v grep|wc -l`
if [ $ProcNumber -le 0 ];then  
   result=0  
else  
   result=1   
fi
#echo ${result}
if [ $result -eq 1 ];then
 echo "has file in transit.."
 while true
 do
  ProcNumber=`ps -ef |grep $PROC_NAME|grep -v grep|wc -l`
   if [ $ProcNumber -le 0 ];then
    echo "download finish!"
    break
   else
    sleep 7
   fi
 done
else
 echo "no file in transit!"
fi
checkroot="/home/lxh/aa/"
cp /dev/null rsync_file
if [ ! -f file.md5 ];then
  find $checkroot -type f -exec md5sum {} \; >>file.md5
else
  for file in $(md5sum -c file.md5|awk -F':' '/FAILED/{print $1}')
    do
      if [ -f $file ];then
      filename_z=$(echo $file|sed 's#/#\\/#g')
      sed -i "/ $filename_z/"d file.md5
      md5sum $file >> file.md5
      echo $file >> rsync_file
      else
      echo $file >>rsync_rm
      fi
    done
  for newfile in $(find $checkroot -type f)
    do
      grep $newfile file.md5 >/dev/null 2>&1
      if [ $? -gt 0 ];then
      md5sum $newfile >> file.md5
      echo "$newfile" >> rsync_file
      fi
    done
fi
for rfile in $(cat rsync_file)
do
echo ${rfile}
done
 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!