I've added a job to root
's crontab
# crontab -l | tail -n 1
*/3,13,29,43 * * * * /root/bin/check_network.sh
#
However, it appears to be running as my normal user, rwb
.
The rwb
account (not the root
account) is getting mail about the job failing, and it's failing because
/root/bin/check_network.sh: line 26: iw: command not found
But of course iw
is at /use/sbin/iw
wchich is on root
's $PATH
but not rwb
's.
What's going on?! How can I run my root cron job?
Update
Changingthe command from iw
to /usr/sbin/iw
seems to have got it working, so there must be some difference in the $PATH
when cron is running compared to a normal bash window.
iw
in the error means that the script has been started, and because it's in/root
it certainly started with root privileges. – Garo Jun 24 '21 at 08:16grep root /etc/aliases
. Also, check the headers of the mail, particularly headers likeTo:
andDelivered-To:
. – cas Jun 24 '21 at 08:52root:rwb
in/etc/aliases
which explains whyroot
's mail is going torwb
. Ta :) – Richard Barraclough Jun 24 '21 at 08:56