Run a shell command when a file is added

前端 未结 6 523
梦毁少年i
梦毁少年i 2020-11-27 20:04

I have a folder named images on my linux box. This folder is connected to a website and the admin of the site has the ability to add pictures to this site. However, when a

6条回答
  •  执念已碎
    2020-11-27 20:16

    #!/bin/bash
    
    tail -F -n0 /var/log/vsftpd.log | while read line; do
      if echo "$line" | grep -q 'OK UPLOAD:'; then
        filename=$(echo $line | cut -d, -f2 |awk '{print $1}')
        filename="${filename%\"}"
        filename="${filename#\"}"
        #sleep 1s
        if [ -s $filename ]; then
          # do something with $filename
          echo $filename
        fi
      fi
    done
    

提交回复
热议问题