Reading a root password with su-to-root shell script
su-to-root is a simple script to give an interactive front-end to su. It can be used in menu entry commands to ask for the root password.
This is extermly useful when you want to use it from menu based shell script. Most menu entries simply start an editor or a game or whatever. But some menu entries would like to give the user the ability to change important settings in the system, that require root privileges. su-to-root script can be used to ask for the root password.
Examples:
To restart Apache web server you need to type command as follows:
$ su-to-root -c “/etc/init.d/apache-perl restart”
Output:
About to execute /etc/init.d/apache-perl restart. This command needs root privileges to be executed. enter root passwd: Password: Restarting apache-perl 1.3 web server....
If command or password failed it will prompt back user with “Try again? (y/n)” prompt.
$ su-to-root -c “/etc/init.d/apache-perl restart”
Output:
About to execute /etc/init.d/apache-perl restart. This command needs root privileges to be executed. enter root passwd: Password: su: Authentication failure Sorry. Incorrect password or command failed. Try again? (y/n)
This kind of flexibility always needed when you write menubased shell script. If your program/command is a X11 program that do not require a terminal then you need to pass -X option to su-to-root command:
$ su-to-root -c “network-admin”
Where,
- -c COMMAND : The command to execute as a string. This option is mandatory.
- -X : The command is a X11 program that do not require a terminal
没有评论▼