1

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

10
  • Is the /mnt/usb0 filesystem mounted with the noexec option?
    – Kusalananda
    Feb 3, 2022 at 10:09
  • No, it isnt. Thanks for pointing that out, I've updated the post.
    – eDonkey
    Feb 3, 2022 at 10:14
  • Can you show us the full contents of /mnt/usb0/fake-hwclock-cron.sh? Oh, and what operating system is this?
    – terdon
    Feb 3, 2022 at 10:25
  • That is the full content, it should only execute this ONE command.
    – eDonkey
    Feb 3, 2022 at 10:27
  • So there is no shebang line?
    – terdon
    Feb 3, 2022 at 10:27

1 Answer 1

1

Based on the output of the mount |grep usb0 it shows that the mount point is mounted by the noexec option and it will prevent you just executing the script but you can do execute it with shell interpreter directly like:

* * * * * sh /path/to/script.sh

for the later error fake-hwclock: not found, you would need to provide the full of the fake-hwclock commnad.

see more about noexec.

1
  • 1
    Sadly I cannot upvote yet, thanks (to everybody) for the help though!
    – eDonkey
    Feb 3, 2022 at 10:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .