Operating System - HP-UX
1843929 Members
1480 Online
110226 Solutions
New Discussion

starting a shell script with root privileges

 
SOLVED
Go to solution
Maciej Szewczykowski
Frequent Advisor

starting a shell script with root privileges

Hello,

I've got a simle & short question.

How to start a shell script (also via cron) as a different user that is currently logged in (in praticular, how to do this with root privileges).

Thx in advance.

maciek
5 REPLIES 5
LiPEnS
Valued Contributor

Re: starting a shell script with root privileges

Hi
Install and configure SUDO
http://www.courtesan.com/sudo/download.html

Regards
Luk Vandenbussche
Honored Contributor
Solution

Re: starting a shell script with root privileges

Hi,

1) interactive : Not possible

2) cron : put it in the crontab of root
Muthukumar_5
Honored Contributor

Re: starting a shell script with root privileges

To execute as a different user then use sudo utility to achive this.


IF you want to start as normal user from root user then

# su - -c <script>

IT will work without asking for passwd except root user.

If you want to start from cron with root user then you should use sudo utility to execute this.

hth.
Easy to suggest when don't know about the problem!
Muthukumar_5
Honored Contributor

Re: starting a shell script with root privileges

You can do with another way of using shell pipe(s) as,

(
echo "root"
sleep 2
echo "passwd for root"
sleep 2
echo ""
sleep 1
echo "exit"
) | telnet localhost

You can execute with any user when he is known about root user passwd. It will not ask root user password on command execution. You can store root user, passwd and script in shell variable and use them with cron tab scripting.

hth.
Easy to suggest when don't know about the problem!
Arunvijai_4
Honored Contributor

Re: starting a shell script with root privileges

You can download sudo from http://h20293.www2.hp.com/portal/swdepot/displayProductInfo.do?productNumber=HPUXIEXP1111

and configuration is available at,
http://www.courtesan.com/sudo/man/sudoers.html

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"