I've edited my root crontab
to periodically execute a script:
sudo crontab -e
Which should execute the following script, located on a mounted USB, as root:
* * * * * /mnt/usb0/fake-hwclock-cron.sh
The script (1) fake-hwclock-cron.sh
then runs the script (2) fake-hwclock
to save the current time:
#!/bin/sh
echo "$(fake-hwclock save)"
The script (2) fake-hwclock
(located in "/sbin/fake-hwclock") then saves the time to the file (3) fake-hwclock.data
on a mounted USB.
The USB is automatically mounted with the following options:
PARTUUID=1c921a37-01 /mnt/usb0 ext4 defaults,auto,users,rw,nofail 0 0
File Permissions:
(1) -rwxrwxrwx 1 pi pi /mnt/usb0/fake-hwclock-cron.sh
(2) -rwxr-xr-x 1 root root /sbin/fake-hwclock
(3) -rwxrwxrwx 1 pi pi /mnt/usb0/fake-hwclock.data
If I understood it correct, for the files (1) fake-hwclock-cron.sh
and (3) fake-hwclock.data
every user can read/write/execute.
For file (2) fake-hwclock
every user can read/execute.
.. but ignoring these permissions for a second, isn't the cron job, which is executed as sudo, executing the script (1) fake-hwclock-cron.sh
with su rights as well?
And what's even more confusing: I can execute both scripts (1) / (2) without su rights in the shell, but I cant execute them with su rights as a cron job.
So, can anyone explain to me why I get a "Permission denied" error?
/bin/sh: 1: /mnt/usb0/fake-hwclock-cron.sh: Permission denied
P.S. I hope i've managed to explain well enough; otherwise please tell me
/mnt/usb0
filesystem mounted with thenoexec
option?/mnt/usb0/fake-hwclock-cron.sh
? Oh, and what operating system is this?