Run a shell command when a file is added

前端 未结 6 534
梦毁少年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:38

    Using ghotis work

    Here is what I did to get the users free space:

    #!/bin/bash
    
    tail -F -n 1 /var/log/vsftpd.log | while read line; do
      if echo "$line" | grep -q 'OK LOGIN:'; then
        pid=$(sed 's/.*\[\([^]]*\)\].*/\1/g' <<< "$line")
        #the operator '<<<' doesnt exist in dash so use bash
        if [[ $pid != *"pid"* ]]; then
          echo -e "Disk 1: Contains Games:\n" > /home/vftp/"$pid"/FreeSpace.txt; df -h /media/Disk1/ >> /home/vftp/"$pid"/FreeSpace.txt
          echo -e "\r\n\r\nIn order to read this properly you need to use a text editor that can read *nix format files" >> /home/vftp/"$pid"/FreeSpace.txt
        fi
    echo "checked"
    #  awk '{ sub("\r$", ""); print }' /home/vftp/"$pid"/FreeSpace.txt > /home/vftp/"$pid"/FreeSpace.txt
      fi
    done
    

提交回复
热议问题