You could strip the environment before you run at
:
echo "command ..." | env - PATH="$PATH" sudo su - otheruser -c "at now"
You can also arrange for sudo
to do this for you by setting the env_reset
option. For example, you could give your user access to run the at
command as otheruser directly (rather than sudo
to root and then to the other user) and then set env_reset with a Defaults
command for that user or that command (see the sudoers man page).
But the above is probably the easiest solution without changing how you're generally doing things today.