I'm trying to parse vsftpd logs to do some extra processing on the successfully uploaded files.
username will be the user so I create the home dir
filename is the file name in the log: it gives a wonky result i.e. "/foo.txt" but that doesn't matter
#!/bin/sh
sudo tail -F /var/log/vsftpd.log | while read line; do
if sudo echo "$line" | grep -q 'OK UPLOAD:'; then
username=$(echo "$line" | cut -d" " -f8 | sed 's/\[\(.*\)\]/\1/')
filename=$(echo "$line" | cut -d, -f2 | sed 's/^[ \t]*//')
home="/home/vsftpd/$username"
if sudo ls "$home$filename" &> /dev/null; then
# do something with $filename
echo "some text"
fi
fi
done
When a file is uploaded I expect the text "some text". I never get that instead I can see it reports:
ls: cannot access /home/vsftpd/user1"/foo.txt": No such file or directory
Although I can run the command in the shell:
$ sudo ls /home/vsftpd/user1"/foo.txt"
/home/vsftpd/user1/foo.txt
I'm guessing permissions related but I've got it running as sudo and I've given the directories full access. Any ideas?