LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-25-2013, 12:19 PM   #1
DiBosco
Member
 
Registered: Nov 2001
Location: Manchester, UK
Distribution: Mageia
Posts: 813

Rep: Reputation: 40
Want to run a script that needs root [to mount network drives] privilege as user


I've dumped my x86 server and have a Raspberry Pi running all the time with my most used files amd mysql server on, and a RAID NAS that holds everything else. The NAS will be asleep for much of the time and wake up at certain times of the day to back-up the Pi and I can wake up on LAN if there's anything archived on it I need to get at. This will save me a stack of money in electricity bills.

I used to mount my network drive in fstab, but now I can't do that (other than the Pi) because most of the time they're not on. I regularly use mount.cifs to mount network drives and it's easy to knock up a script to launch what I want. I really would like to have a desktop icon to click on to run the scripts, so I can mount the drives, but mount.cifs needs root privilege. So, is there a way to give a scripts like this the requisite privilege? I know I could probably use smb4k, but I don't think it works very well in general and why do that when I can run a little script once and forget about it?

Thanks!

Last edited by DiBosco; 02-27-2013 at 06:02 AM.
 
Old 02-25-2013, 12:28 PM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,880
Blog Entries: 1

Rep: Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871
sudo is your friend
 
Old 02-25-2013, 12:29 PM   #3
DiBosco
Member
 
Registered: Nov 2001
Location: Manchester, UK
Distribution: Mageia
Posts: 813

Original Poster
Rep: Reputation: 40
...

Last edited by DiBosco; 02-25-2013 at 12:36 PM.
 
Old 02-25-2013, 12:54 PM   #4
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,880
Blog Entries: 1

Rep: Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871
Could be quite useful if you want to run a script with root-rights.
 
Old 02-25-2013, 02:15 PM   #5
eSelix
Senior Member
 
Registered: Oct 2009
Location: Wroclaw, Poland
Distribution: Arch, Kubuntu
Posts: 1,281

Rep: Reputation: 320Reputation: 320Reputation: 320Reputation: 320
You can still use fstab. Just add options "noauto,user", First disable automatic mount on system boot, and second allow unprivileged users to mount it when necessary. Another possibility is using some automount tool (for example I use "autofs"). It will check if someone is trying access the network resource and then do automatic mount. After some time of inactivity it will unmount.
 
2 members found this post helpful.
Old 02-26-2013, 04:32 AM   #6
DiBosco
Member
 
Registered: Nov 2001
Location: Manchester, UK
Distribution: Mageia
Posts: 813

Original Poster
Rep: Reputation: 40
Thanks for the suggestions, folks, I will try them.
 
Old 02-27-2013, 06:50 AM   #7
DiBosco
Member
 
Registered: Nov 2001
Location: Manchester, UK
Distribution: Mageia
Posts: 813

Original Poster
Rep: Reputation: 40
OK, in the end I edited sudoers, added permissions for me to run specific files in /usr/local/sbin/ that runs mount.cifs with all the appropriate parameters and then wrote a script that runs the script in /usr/local/sbin/ by clicking on a shortcut on the desktop and putting sudo at the front. I had to do #/bin/bash on the first line and I had to make sure run in terminal was selected when I made the shortcut. I think that's one time when sudo is acceptable!

Last edited by DiBosco; 02-27-2013 at 06:53 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to run a shell script as root (when user is not root) taylorkh Linux - Newbie 10 09-12-2008 06:05 PM
How can I have a script owned as root and run as root by a user: setuid? stickey bit? abefroman Linux - Newbie 9 04-19-2008 05:15 PM
run a specific script with root privilege as any user(possibly with ssh) z940303 Programming 5 09-05-2007 08:20 PM
mount smb drives as non-root user? cdhgee Linux - Software 5 09-05-2007 07:38 AM
mount drives from user instead of root gonavy Linux - Newbie 2 11-29-2003 08:53 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:59 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration