Running the following script as myself works but not when I use sudo
. As you can probably tell, the touch
error is just to make sure something is written to the log file.
dave@pi1:~ $ ./test.sh
touch: cannot touch '/asdf/asdf/asdf': No such file or directory <--- As expected
dave@pi1:~ $ sudo ./test.sh
./test.sh: 2: ./test.sh: Syntax error: redirection unexpected <--- why this not work?
dave@pi1:~ $
The script:
LOG_FILE=/var/log/usbhook
exec > >(tee -a ${LOG_FILE} )
exec 2> >(tee -a ${LOG_FILE} >&2)
touch /asdf/asdf/asdf
The aim is to have a script fired when I plug in a USB stick so I'm assuming it should work when ran using sudo.