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?

[Webinar] Streamline your web hosting managementRegister Today

x
 
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 convenient...you can use usermount instead, but you may have to edit /etc/fstab)

best of luck to you!
0
 
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
The new generation of project management tools

With monday.com’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.

 
guiyuCommented:
ozo's comment is more to the point, on 2nd thought.
0
 
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
All Courses

From novice to tech pro — start learning today.