Solved

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

Posted on 2009-04-11
9
1,146 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
Envision that you are chipping away at another e-business site with a team of pundit developers and designers. Everything seems, by all accounts, to be going easily.
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now