open shell as root, execute and close

I need to execute a command as root (such halt command) then return to by normal shell. How ??
sfenatiAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

guiyuCommented:
Provided your singol command is not a shell script (csh,sh,perl), you can

1)first change the owner of singol to root

chown root singol

2)then do a setuid, so that whoever execute that file is in effect running it as root:

chmod u+s singol

0
ozoCommented:
su root -c singol
0
guiyuCommented:
ozo's comment is more to the point, on 2nd thought.
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

sfenatiAuthor Commented:
Edited text of question.
0
ozoCommented:
su root -c /etc/halt

(but if you halt the machine, how can you return to your shell?)
0
s_turner99Commented:
I think ozo got it already, but you may need to use single quotes to inhibit shell evalution of the command to be executed.  For instance, mounting a floppy using the mount command required root priviledge:

su -c 'mount -t vfat /dev/fd0 /mnt/floppy'

You'll be prompted for the root password.  After the command executes you'll be back to an ordinary user session.  (Note: the sample command above will cause all the files on the floppy to be owned by root...not very convenient...you can use usermount instead, but you may have to edit /etc/fstab)

best of luck to you!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux

From novice to tech pro — start learning today.