Cron file permission help

I have a cron set up to run every 5mins to fix file permissions for the SFTP server I have up.


Here is my script:

FOLDERS=/Volumes/Server/Trainer/*



logger Cron Perm Script Start



for f in $FOLDERS

do

if [ $f != "/Volumes/Server/Trainer/scripts" ]; then

user=`stat -f %u $f/uploads`

folder="${f}/uploads"

response=`chown -R $user $folder`

responsetwo=`chmod -R 770 $folder`

logger response $response $responsetwo

fi

done

logger Cron Perm Script End

exit 0



If I execute the script myself as root it works fine and all the permissions get fixed. It gets run fine through the cron service but it won't fix the permissions. I've tried to debug this numerous ways but haven't figured out what I'm doing wrong.


$folder has the right path.

$user is the right user id.


the logger calls show up in the console so I know it's running.

11-09-28 11:10:00.960 AM root: Cron Perm Script Start

11-09-28 11:10:00.965 AM root: response

11-09-28 11:10:00.969 AM root: response

11-09-28 11:10:00.975 AM root: response

11-09-28 11:10:00.980 AM root: response

11-09-28 11:10:00.985 AM root: response

11-09-28 11:10:00.990 AM root: response

11-09-28 11:10:00.994 AM root: response

11-09-28 11:10:00.999 AM root: response

11-09-28 11:10:01.004 AM root: response

11-09-28 11:10:01.009 AM root: response

11-09-28 11:10:01.013 AM root: response

11-09-28 11:10:01.018 AM root: response

11-09-28 11:10:01.023 AM root: response

11-09-28 11:10:01.027 AM root: response

11-09-28 11:10:01.032 AM root: response

11-09-28 11:10:01.037 AM root: response

11-09-28 11:10:01.041 AM root: response

11-09-28 11:10:01.046 AM root: response

11-09-28 11:10:01.050 AM root: response

11-09-28 11:10:01.055 AM root: response

11-09-28 11:10:01.061 AM root: response

11-09-28 11:10:01.065 AM root: response

11-09-28 11:10:01.070 AM root: response

11-09-28 11:10:01.078 AM root: response

11-09-28 11:10:01.083 AM root: response

11-09-28 11:10:01.089 AM root: response

11-09-28 11:10:01.095 AM root: response

11-09-28 11:10:01.100 AM root: response

11-09-28 11:10:01.106 AM root: response

11-09-28 11:10:01.112 AM root: response

11-09-28 11:10:01.118 AM root: response

11-09-28 11:10:01.124 AM root: response

11-09-28 11:10:01.129 AM root: response

11-09-28 11:10:01.134 AM root: response

11-09-28 11:10:01.140 AM root: response

11-09-28 11:10:01.145 AM root: response

11-09-28 11:10:01.149 AM root: response

11-09-28 11:10:01.151 AM root: Cron Perm Script End



Any help is greatly appreciated.



Thanks.

Posted on Sep 28, 2011 11:13 AM

Reply
22 replies

Sep 28, 2011 4:18 PM in response to Linc Davis

i was hoping for possible errors but it produces nothing. not really sure how to debug this.


if i run the script from terminal as root it works perfectly and changes the owner and permissions properly. when it runs through the cron service only the permissions get changed properly. the cron runs as root so i'm not sure what the issue is.


if the cron user didn't have permissions to do chown, it wouldn't be able to do the chmod command either right?

Sep 29, 2011 9:57 AM in response to s-chilly

hmmm it's definitely something with chown privs executing through the cron service. I've tried some direct chmod commands in the cron file:


chmod -R user_id /Volume/Server/Trainer/username/uploads

chmod -R username /Volume/Server/Trainer/username/uploads


Neither work.


So it's nothing to do with my script building the file paths. hmmmmmm.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Cron file permission help

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.