Solved

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

Posted on 2009-04-11
9
1,152 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Microsoft Certification Exam 74-409

VeeamĀ® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
unable to put logic for reading multiple repo in a single file 4 73
Post Clonezilla image restore issue 6 67
asp web application 3 43
SSH setup on ASA 5505 17 57
Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
Fine Tune your automatic Updates for Ubuntu / Debian
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmakerā€¦
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

697 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