I am running a smartd-runner script that user run-parts to execute all scripts in a given directory. This script is in turn executed by smartd daemon of smartmontools. It appears to be running as root looking at the top command output.
#!/bin/bash
tmp=tempfile
cat >$tmp
run-parts --report --lsbsysinit --arg=$tmp --arg="$1" \
--arg="$2" --arg="$3" -- /etc/smartmontools/run.d
rm -f $tmp
The issue is that it does not in practice appear to be running as root or in fact as any user at all. There is only a single script in run.d directory. That script prints the $USER variable. When executed manually it prints the current username though it doesn't change to root after su command for some reason. When the smartd-runner script is executed by smartd it prints nothing for the $USER variable, not even a empty line thought it does print literal strings. Both scripts have been chmod'ed to 700.
Why is this happening?