2

I am using Raspbian Jessie. I have a cron job for pi user as follows:

SHELL=/bin/bash
@reboot /path/to/execute_script.sh

The script I am executing involves creating directories on a mounted USB flash drive at /media/pi/KINGSTON

But when I look at the log of the execution it says that I have no permissions while creating directories inside /media/pi/KINGSTON:

Creating /media/pi/KINGSTON/some_dir/another_dir
mkdir: cannot create directory ‘/media/pi/KINGSTON’: Permission denied 

Here are the permissions on the mounted USB drive:

$ getfacl /media/pi/KINGSTON
getfacl: Removing leading '/' from absolute path names
# file: media/pi/KINGSTON
# owner: pi
# group: pi
user::rwx
group::---
other::---

I am suspicious that the job is not executed with pi user, because if I use relative path to the script ~ it is not recognized. Also $USER variable is not set when echoed from the cron job.

Any ideas what is going on?

1 Answer 1

2

cron may still be using $LOGNAME instead of $USER and $HOME instead of ~, which shouldn't be used in scripts anyway.

In any case, the error message suggests /media/pi/KINGSTON may not even exist. Perhaps the thumb drive is not yet mounted at the moment when cron executes your script, or it is being mounted and the mount script didn't apply the permissions yet.

Add some logging to your script (I would go for mount > /tmp/my.log) and see what happens. The log file must be created by the pi user, and you will see if the thumb drive is really mounted at this point.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.