How do i change to super user then revert back to ordinary user ,using shell script?

Hi all,

I am trying to eject the cdrom from a livecd after certain stage...
Now assuming that it is possible to eject,please consider my issue!!!

The OS boots into a regular user by default...so i am unable to use the eject command to push out the drive...
However if i try pfexec eject it works....but then again it works only when the system is completely up and running not at some intermittent stage in the boot process.

How do i change the my id to a Superuser then execute the eject command ,then once the eject is done with, i would like to revert back to the ordinary user?
Secondly this code should be incorporated into one of the boot scripts,
So that after a certain stage during the boot, the drive automatically ejects......

How do i do it.....

PS:i urge you to consider that ejecting the media on a livecd is possible.

Thanks

You can try using sudo with the eject command , without password.sudo works like a charm!

put the user that should change to superuser into the /etc/sudoers file.
then run sudo with the --preserve-environment flag so you can use your varibales that you set under the first user also in the superuser. then exit from su mode with exit :wink:

i am using a flavor of solaris...
There is no command called sudo..
If i have to enter as super user then i will use
su - <account name>
will take you to the subsequent account

But i did look up the man pages and found a way out!!!
bash 3.2$: su - root -c eject
password: ******
<i am able to eject the drive>
bash3.2$:

and so i return back to default user...... :slight_smile:
so all my queries are solved...
However i am curious to know, since i have provided for a password, the system will ask for a passwd conformation...
But if dont ,then will it just skip the passwd thing, and proceed with ejecting??