Link to home
Start Free TrialLog in
Avatar of tzvish
tzvishFlag for Israel

asked on

Permission Denied while running a bash script via cron on MNT/NAS, How to solve this?

Hello,

I have nas setup on my hosting server and doing great running my bash script via root with putty connection.
Whenever I try to run these bash script that basically does "ls" on the nas folder and copies mysqldump *.gz to it - I get a permission denied error.
this doesn't occur when running the script with root.

I have tried for hours to get around this, cron runs the bash script under it's cpanel username in this case, which I guess doesn't have root's permissions - Can you please help me in how can get my user to make modifications to the nas files?
this was my mount command:

mount -t cifs -o username=hiddenusername,password=hiddenpassword //hiddenIP/nas.nas.XXX /mnt/nas
(parts of the command were hidden for security reasons)

this is an example output of the script while running from my cpanel user's cron:
/home/XXX/mybackup.sh: line 5: /mnt/nas/backups/XXX/XXX_04_11_09.gz: Permission denied
mysqldump: Got errno 32 on write
ls: /mnt/nas/backups/XXX/XXX_04_11_09.gz: Permission denied
ls: /mnt/nas/backups/XXX/XXX*: Permission denied
(parts of the command were hidden for security reasons)

I have noticed that whitin the NAS my group name and username for files and folders are different and labeled as numbers.
Please provide help in which my cpanel cron user can make file modifications to that nas folder ?
ASKER CERTIFIED SOLUTION
Avatar of Morne Lategan
Morne Lategan
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tzvish

ASKER

Thanks, trying this out, any idea how this can be made for multipule users?
( i have about 6 cpanel account i want to set the cron commands to)
Avatar of tzvish

ASKER

Thanks, this worked great for my test cpanel user,

I got these 2 warnings:
WARNING: 'file_mode' not expressed in octal.
WARNING: 'dir_mode' not expressed in octal.


and i still don't know, how can i set it so the 5 other cpanel created users can is this ?
Avatar of tzvish

ASKER

Cant get this to work for all my users, if i set the uid and gid for that current user they can modify files but then other users can't -
there must be a way to find a cummon permission setting for all these cpanel users, i tried to use root/root but that failed :(

any ideas?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Oops, sorry, ewest02 is right, prepend the zero :)

Make sure all the users belong to the same group, then use 0770, that is: binary 111111000, or in Linux terms, rwxrwx--- which says that the linux user you mounted it as has read, write and execute permissions, the group you mounted it as has read, write and execute permissions and the rest has nothing.
Avatar of tzvish

ASKER

Hi, thanks - I cant get my nas folder to be 0755  - thus making "others" write files on it.
even when mounting with 0755 for dir and file, when using ls -l i get this:

drwxrws---+  3 root root    0 Apr 11 15:32 nas/

any idea why ?
0755 = rwxr-xr-x

That means no write for the others. Try 0777 if you want "other" to have write permissions. Also, have a look inside the nas folder instead of at the nas folder, that is:

cd /path/to/nas
ls -l

Then do:

umount /path/to/nas
chmod 777 /path/to/nas

And then mount it again.
Avatar of tzvish

ASKER

Created a diffrent mounted folder for each of the cpanel users, and now it works great