I'm installing a watcher system for my server, this will basically watch my directories for any change/delete/modify/create ... so I can call a .sh
file in the watcher when those events occur so I have these in my watcher.sh file
#!/bin/bash
LOGFILE=/etc/watcher.log
chmod 000 -R $1
chown root $1
echo "$(date +%Y-%m-%d);$(date +%H:%M:%S);$1;$3;$2;watcher.sh" >> $LOGFILE
It works fine when I upload a file called a.txt
but if I upload a file with space in their names nothing happens. In the log file I have
2017-06-04;18:37:34;/home/domain/public_html/upload/a b.txt;IN_CREATE;128;watcher.sh
chmod: cannot access `/home/domain/public_html/upload/a': No such file or directory
chmod: cannot access `b.txt': No such file or directory
chown: cannot access `/home/domain/public_html/upload/a': No such file or directory
chown: cannot access `b.txt': No such file or directory
the space in the name is messing this up. How can I fix this? Also why can I still delete the newly uploaded file from cpanel I tough by changing ownership to root it would be inaccessible in the cpanel.
You may place quote characters around the parameters such as:
chmod 000 -R "$1"
chown root "$1"
The quotes should resolve the issue with the spaces via the parameters in the shell script.