Still learning and I'm getting lost with IFS=
#!/bin/bash
inotifywait -m -r --excludei '(.txt$|.old$|.swp$|.swx$|.swpx$|.zip$)' /path/to/watch -e create |
while read path action file; do
cd $path
USER="$(stat -c %U $file)"
echo "To: User <[email protected]>
CC: Support <[email protected]>
From: $USER <[email protected]>
Subject: $USER has Uploaded a new File
The user '$USER' uploaded the file '$file' to '$path'" > /mnt/remote/ian/temp2.txt
cat /path/to/temp/file.txt | ssmtp [email protected]
rm /path/to/temp/file.txt
done
This was my first ever script and it works great as long as there are no spaces in the the file names that get uploaded. I've read some scripts that use IFS= 'whatever' to define the field separators but I don't want to mess around with this while it's in production; it works, but it annoys me when I can't get the username of the user who uploaded the file. Please give me a hint.
\0-- the only character which can't legally exist in a filename -- there literally isn't a 100%-reliable solution possible."$file"or"$path"? That's essential to avoid bugs; shellcheck.net will point out any places where you're skipping it.create(flagging when a file is created, but not necessarily when content is done being written to it), as opposed toclose_write?