Solved

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

Posted on 2009-04-11
9
1,151 Views
Last Modified: 2012-05-06
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 ?
0
Comment
Question by:tzvish
  • 5
  • 3
9 Comments
 
LVL 7

Accepted Solution

by:
Morne Lategan earned 251 total points
ID: 24123096
Hi there,

mount -t cifs -o username=hiddenusername,password=hiddenpassword,uid=your_linux_user,gid=your_linux_group,file_mode=700,dir_mode=700 //hiddenIP/nas.nas.XXX /mnt/nas

(Add the local user and group)
0
 
LVL 1

Author Comment

by:tzvish
ID: 24123210
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)
0
 
LVL 1

Author Comment

by:tzvish
ID: 24123288
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 ?
0
The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

 
LVL 1

Author Comment

by:tzvish
ID: 24123395
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?
0
 
LVL 4

Assisted Solution

by:ewest02
ewest02 earned 249 total points
ID: 24124521
If you create the mount point as root, open the perms for the other non-root users,
   dir_mode=0755 file_mode=0755

Alternatively, create a mount point for each user. /mnt/nas/jdoe, /mnt/nas/mmouse, ...

Prepend a 0 (zero) to the mode values to remove those warning messages 700 -> 0700
0
 
LVL 7

Expert Comment

by:Morne Lategan
ID: 24124898
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.
0
 
LVL 1

Author Comment

by:tzvish
ID: 24124934
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 ?
0
 
LVL 7

Expert Comment

by:Morne Lategan
ID: 24133137
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.
0
 
LVL 1

Author Closing Comment

by:tzvish
ID: 31569220
Created a diffrent mounted folder for each of the cpanel users, and now it works great
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developer portfolios can be a bit of an enigma—how do you present yourself to employers without burying them in lines of code?  A modern portfolio is more than just work samples, it’s also a statement of how you work.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
This video teaches users how to migrate an existing Wordpress website to a new domain.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question