You are right, the jobs in
/etc/cron.daily (and weekly/monthly, etc.) are always
executed as user
root but you can simply swith the user from within the script
and call that very script again as that other user, including all supplied
arguments (although there won't be any in a
# If started as root, then re-start as user "gavenkoa":
if [ "$(id -u)" -eq 0 ]; then
exec sudo -H -u gavenkoa $0 "$@"
echo "This is never reached.";
echo "This runs as user $(id -un)";
# prints "gavenkoa"
When the script is started as user
root it will detect so and
re-execute itself via
sudo -H -u gavenkoa, that is: as
gavenkoa. This requires no special entries in
root is always allowed to switch to any user.
exec replaces the current process with the new
sudo … call
and never returns. That's why you don't need an