Skip to main content
Tweeted twitter.com/StackRaspi/status/852262060473946112
edited tags
Link
CuriousGuy
  • 1k
  • 1
  • 9
  • 7
Source Link
CuriousGuy
  • 1k
  • 1
  • 9
  • 7

User cron job permission denied to directory owned by the user

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?