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 ??
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

s_turner99Connect With a Mentor Commented:
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 can use usermount instead, but you may have to edit /etc/fstab)

best of luck to you!
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

su root -c singol
The new generation of project management tools

With’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

ozo's comment is more to the point, on 2nd thought.
sfenatiAuthor Commented:
Edited text of question.
su root -c /etc/halt

(but if you halt the machine, how can you return to your shell?)
All Courses

From novice to tech pro — start learning today.