Running a command or script as root


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Running a command or script as root
# 1  
Old 05-25-2005
Question Running a command or script as root

I'm writing an application (Progress language) that needs to:
1) load the contents of a cron table into the Progress application;
2) display this information in a human manner and allow a select group of people to update it (these people are logged in as themselves, not as root);
3) save everything back to the cron table (probably just overwrite the existing file with the newly generated one).

My questions relate to (1) and (3). The cron file is located in a directory called /var/spool/cron/crontabs/
-r-------- 1 root sys 1978 May 24 10:58 qadbatch

As you can see, only root can Read and Write to this file (and we like it this way!!).

Any ideas on how to read and overwrite this file without being root?

Notes:
A- The Progress application can run any Unix commands or scripts and retrieve their output (but it cannot run interactive commands such as 'crontab -e').

B- Users do not have access to the crontab command.

Thanks!!

Réal
# 2  
Old 05-26-2005
Quote:
Any ideas on how to read and overwrite this file without being root?

No way ...
# 3  
Old 05-26-2005
maybe you could try ...


1. write a cron script --- running under root --- that would ...

a. regularly copy /var/spool/cron/crontabs/qadbatch to /somedir/somefile
b. regularly check for changes in /somedir/somefile as compared to /var/spool/cron/crontabs/qadbatch. changes made to /somedir/somefile are incorporated into the qadbatch crontab.


2. write a script that lets the users edit /somedir/somefile and logs those edits. since the possibility of mischief exists, you might want to add more security checks to the edit script --- i.e., require a random password that you give to the users, etc. --- just to be on the safe side.
# 4  
Old 05-27-2005
OK, I found a few ways to do that but I was approaching the problem from the wrong angle.

You cannot modify the cron file owned by root, or so it says in man. You have to use the crontab command. This being established, how do I allow a user to modify another user's cron table? I first thought of sudo but it's not installed here and I would have to convince the sys-admins to do this - more problems...

Remote Shell! That is the way to go! You setup the user who owns the cron table to accept remote access from select users (create a .rhosts file in this user's home dir).

Then, those select users can rsh (remsh on certain systems) their way into the owner's crontab entry:
$ rsh <server-name> -l <cron-userid> "crontab <new-cron-file>"

Voila!

Thanks to those who replied.

Réal
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Running a script as root in the script

hi all, i think i have got the solution for this but want to run it past you guys first when i run a script sometimes its necassary to sudo to root so it can create users, chmod etc etc, the normal way for me doing this is just to simply run the script as root but i have created a user... (11 Replies)
Discussion started by: robertkwild
11 Replies

2. UNIX for Beginners Questions & Answers

Running a command as another non-root user

Hi, I am trying to run a command within my KSH script as another user due to permission issues, now both users are non root. I have tried the following command and was unsuccessful: echo "<password>" | sudo -S -u <username> -k command Can I use sudo to run a command as a non-root user? (5 Replies)
Discussion started by: MIA651
5 Replies

3. Shell Programming and Scripting

Root running a script calling to scp using user "xyz" is not authenticating!

Close duplicate thread. (0 Replies)
Discussion started by: denissi
0 Replies

4. Shell Programming and Scripting

Running a script as root but with different users inside

Hi All, my script.sh has the below lines, and i need to run the script as root or wam. please tell me if this will work #!/bin/bash sudo -t wam /usr/local/wam/stopwam -r ------- this needs run as wam user /usr/local/web/stopweb -a --- this needs to run as... (18 Replies)
Discussion started by: nanz143
18 Replies

5. UNIX for Dummies Questions & Answers

Run script as root from command line

I have a script (ksh) that has permissions 775 and owned by root.system. This script takes the parameter of a full file name and chmods the file to 666 and changes ownership to user smith.staff. ex: modify_file.ksh /home/smith/filea modify_file.ksh has 775 and root.system ownership. The... (1 Reply)
Discussion started by: mlacriola
1 Replies

6. Solaris

How to know the script/command executor as root?

In my ENV every one has sudo access to "XYZ" user and they run the script any time. can you please suggest how could I identify who has executed script after sudo user XYZ ? OS : sunSolaris process of login Step 1 : user login with his own username and PWD Step 2 : sudo to XYZ user... (1 Reply)
Discussion started by: yogendra.barode
1 Replies

7. Shell Programming and Scripting

Script for running root based C++ code

Hi all, I have to run C++ file using root programming, using following commands: $root -l root .L TwoTrees.C++ root TwoTrees t root t.Loop() root.q I wonder if I can write script to do the following. Thanks Pooja (12 Replies)
Discussion started by: nrjrasaxena
12 Replies

8. Shell Programming and Scripting

Issue running script as root

1) Environment:Red Hat Linux, bash shell Script to be run owned by user :myUser Home environment of myUser: pathto/home 2) ESP agent with root access will run JobXXX.sh su - myUser -c "/pathto/home/bin/script.sh" where script.sh has some echo statements and an exit statement in the end... (4 Replies)
Discussion started by: cj09
4 Replies

9. Cybersecurity

Running script through SSH as root

Hi all, I have a situation where I have a shell script that I need to run remotely on multiple *nix machines via SSH. Unfortunately, some of the commands in it require root access. I know that best practices for ssh entail configuring it so that the root account cannot log in, you need to... (4 Replies)
Discussion started by: irinotecan
4 Replies

10. Shell Programming and Scripting

As root , running script as different user with su - problem

Dear All I am running into a situation where I am running a script as another user lets say oracle using su command as below, and the script fails because the .profile of oracle is not executed so the environment variables are not set. cat /etc/passwd | grep oracle... (4 Replies)
Discussion started by: dbsupp
4 Replies
Login or Register to Ask a Question