LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 09-08-2008, 10:34 AM   #1
taylorkh
Senior Member
 
Registered: Jul 2006
Location: North Carolina
Distribution: CentOS 6 on my desktop, Ubuntu 12.04 LTS on my server, Ubuntu 12.04 on my netbook and the wife's PC
Posts: 1,204

Rep: Reputation: 96
Question How to run a shell script as root (when user is not root)


Ubuntu 8.04 - Gnome - here is the the issue:

I wrote a shell script to copy the data under /home to a USB drive for backup. I intended to schedule the job to run every day at 1 AM. However, while the PC will go into standby as I want it to, it will not wake up to run the script. I have another PC of the same model and I can wake it up by using the auto power on in BIOS - but not this one(?)

The script will copy data for 2 user accounts, mine and the wife's thus it must be run with root permissions. Her account is not a sudoer and it should not be. Her account is generally logged onto the PC and she would be the one to execute the script manually until I figure out how to resolve the power on issue. What I need to do is create a launcher which will run the script with root permissions without her having to logon with my credentials in order to sudo the script.

I believe I have come across a way to make a program or script run as root without having to be root or know the root password. How to do it escapes me at the moment.

Thanks for any advice.

Ken
 
Old 09-08-2008, 10:37 AM   #2
b0uncer
Guru
 
Registered: Aug 2003
Distribution: CentOS, OS X
Posts: 5,131

Rep: Reputation: Disabled
Why not add your wife's user account to sudoers and configure it so that only your script can be run (and then prevent her from modifying the script)? For the time being.

Last edited by b0uncer; 09-08-2008 at 10:39 AM.
 
Old 09-08-2008, 11:36 AM   #3
taylorkh
Senior Member
 
Registered: Jul 2006
Location: North Carolina
Distribution: CentOS 6 on my desktop, Ubuntu 12.04 LTS on my server, Ubuntu 12.04 on my netbook and the wife's PC
Posts: 1,204

Original Poster
Rep: Reputation: 96
That is certainly a possibility. However, she is not happy about having to push the power button and type in her password to get back in after the PC goes to standby (as opposed to just bumping the mouse in XP - until service pack 3 destroyed my finely crafted install). She uses the PC for Web and email and that is about as far as her interest goes.

Still, this is more of an intellectual challenge for me. I recall that early versions of Red Hat required root permission to connect to the Internet with a modem or to burn a CD with XCDRoast. There was a way to fix those although I do not remember how. I guess I need to see if I can find any of my old notes.

Ken
 
Old 09-09-2008, 01:32 AM   #4
darthaxul
Member
 
Registered: Aug 2008
Distribution: Gentoo; Funtoo
Posts: 206

Rep: Reputation: 18
i never heard of that

I dont know anything like what u tring to do but in order to write data to disk just set permission on usb drive to allow her to write to the disk.
you dont need to run script as root if its just copy /home paste /usb.
 
Old 09-09-2008, 09:52 AM   #5
taylorkh
Senior Member
 
Registered: Jul 2006
Location: North Carolina
Distribution: CentOS 6 on my desktop, Ubuntu 12.04 LTS on my server, Ubuntu 12.04 on my netbook and the wife's PC
Posts: 1,204

Original Poster
Rep: Reputation: 96
Thanks darthaxul. I just reviewed permissions on the various directories and files under /home and see that they are 755 and 644. Umask is 022. This is my first experience with setting up a Linux box with multiple accounts where another user will actually logon and use the PC (other than for testing or to share a printer or folder with Samba). I guess I was expecting a default Umask of 066 where each user's files would be private.

Regardless, my script checks to see if the USB drive is mounted, if not it mounts it, does the cp then umounts the USB drive. At a minimum the account running the script must be able to execute mount and umount. I have tried granting these permissions in /etc/sudoers with NOPASSWD: however, I must have a syntax error as I do not get the result I expect. I will keep working on it.

Ken

Last edited by taylorkh; 09-10-2008 at 10:47 AM. Reason: typo :-(
 
Old 09-09-2008, 01:26 PM   #6
CJS
Member
 
Registered: May 2008
Location: California, USA
Distribution: Ubuntu 8.10
Posts: 247

Rep: Reputation: 49
One thing to keep in mind with the sudoers file is that the order of the rules matters. So to make sure the sudoers line that you add isn't overridden by some other rule, be sure to add your rule to the end of the file. Here is an example of how to use the NOPASSWD syntax in case you haven't gotten it working all ready:
Code:
john ALL = NOPASSWD: /path/to/cmd1, /path/to/cmd2, path/to/cmd3
Let me know if you get it working OK.
 
Old 09-10-2008, 10:55 AM   #7
taylorkh
Senior Member
 
Registered: Jul 2006
Location: North Carolina
Distribution: CentOS 6 on my desktop, Ubuntu 12.04 LTS on my server, Ubuntu 12.04 on my netbook and the wife's PC
Posts: 1,204

Original Poster
Rep: Reputation: 96
As they say in the movies "belay my last" - I have explored the permissions under /home a little more and am back to my original position that my script should be run as root. For example:
Quote:
ken@taylor9:~$ sudo ls -l /home/ken/.config
total 16
drwx------ 3 ken ken 4096 2008-08-29 12:52 compiz
drwx------ 2 ken ken 4096 2008-08-29 13:23 tracker
-rw------- 1 ken ken 630 2008-08-29 12:24 user-dirs.dirs
-rw-r--r-- 1 ken ken 5 2008-08-29 12:24 user-dirs.locale

ken@taylor9:~$ sudo ls -l /home/patsy/.config
total 20
drwx------ 3 patsy patsy 4096 2008-08-29 13:12 compiz
drwx------ 2 patsy patsy 4096 2008-08-29 18:21 gtk-2.0
drwx------ 2 patsy patsy 4096 2008-08-29 13:12 tracker
-rw------- 1 patsy patsy 630 2008-08-29 13:12 user-dirs.dirs
-rw-r--r-- 1 patsy patsy 5 2008-08-29 13:12 user-dirs.locale
It would appear that only the account owner or root can copy all files under their personal /home/user directory. Only root can copy all files for ALL users so I guess I am back to my original question of how to run a script as root when the user is not root does not have the root password.

Ken
 
Old 09-10-2008, 04:35 PM   #8
darthaxul
Member
 
Registered: Aug 2008
Distribution: Gentoo; Funtoo
Posts: 206

Rep: Reputation: 18
another option

maybe you can run it as a cron job. just make sure the job runs as root. that way the user doesnt even have to run anything, its automatic.
 
Old 09-10-2008, 05:20 PM   #9
taylorkh
Senior Member
 
Registered: Jul 2006
Location: North Carolina
Distribution: CentOS 6 on my desktop, Ubuntu 12.04 LTS on my server, Ubuntu 12.04 on my netbook and the wife's PC
Posts: 1,204

Original Poster
Rep: Reputation: 96
Back at the beginning of the thread I indicated that I had planned to run the job as with the scheduler - and it will work if I schedule it with root credentials. The problem is that this particular PC will not wake from standby to run the job.

Windoze will let me wake the PC from within the scheduler. I do not know if/how that can be done with cron.

Ken
 
Old 09-12-2008, 06:40 PM   #10
darthaxul
Member
 
Registered: Aug 2008
Distribution: Gentoo; Funtoo
Posts: 206

Rep: Reputation: 18
wasdm

so u want it to go into standby, but have the ability to wakeup and run that script/job?
 
Old 09-12-2008, 07:05 PM   #11
taylorkh
Senior Member
 
Registered: Jul 2006
Location: North Carolina
Distribution: CentOS 6 on my desktop, Ubuntu 12.04 LTS on my server, Ubuntu 12.04 on my netbook and the wife's PC
Posts: 1,204

Original Poster
Rep: Reputation: 96
That is it exactly.

The PCs are Dell Dimension 4600s. The "newer" one with a 2.8 GHz processor seems to wake up from standby when set in BIOS to "automatic power on" at appointed time (about a minute before the cron job) just fine. The older PC with a 2.66 GHz processor will not wake from standby using the same method. I have upgraded the bios on both to the latest A12 from Dell.

I think I will try putting the offending PC in hibernate and see if BIOS can awaken it.

Last edited by taylorkh; 09-12-2008 at 07:13 PM. Reason: correct BIOS rev
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Run shell script as root automatically elempoimen Linux - Software 8 06-20-2010 02:24 AM
How to run root privileged Linux command as normal user via shell shell tcegrid Linux - Newbie 1 06-23-2008 04:38 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 06:15 PM
allow sudo for www user to run root shell script cccc *BSD 12 07-23-2005 04:48 PM
Need to run shell script as root kaloyer Programming 4 06-27-2004 10:01 AM


All times are GMT -5. The time now is 11:36 PM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration