I am using vsftpd and I want to extract the file name from successful uploads. Log example:
Tue Feb 6 11:49:25 2018 [pid 13018] [xyz] OK UPLOAD: Client "1.2.3.4", "/filename.zip", 131072000 bytes, 19607.40Kbyte/sec
Tue Feb 6 11:49:25 2018 [pid 13017] [xyz] OK UPLOAD: Client "1.2.3.4", "/filename.zip", 131072000 bytes, 24426.38Kbyte/sec
Tue Feb 6 11:49:30 2018 [pid 13018] [xyz] OK UPLOAD: Client "1.2.3.4", "/filename.zip", 131072000 bytes, 25387.19Kbyte/sec
I am using this code:
#!/bin/sh
tail -F /var/log/vsftpd.log | while read line; do
if echo "$line" | grep -q 'OK UPLOAD:'; then
line=$(echo "$line" | tr -s " ")
filename=$(echo "$line" | cut -d, -f2)
echo "$filename"
fi
done
The problem is if the file name has a comma inside, it will not work properly.