Operating System - Linux
1838068 Members
4754 Online
110124 Solutions
New Discussion

Re: How to write a special shell menu ?

 
SOLVED
Go to solution
yyghp
Super Advisor

How to write a special shell menu ?

I have a handheld device which can telnet to our Unix/Linux servers to run an application, it has a full functional keyboard with all keys.
I need to force all users who login to the servers via such device to run a shell script right after they login, without prompting the commandline, like this:

************************
1. Run Application
2. Change Password
3. Logout
************************

I need to restrict all users to access only the options above, they should not be able to do anything else except the actions above.
How to prevent them from using "Ctrl + C" or something else to break the shell and going into the Prompt. That is, they don't need to run "ls", "vi"... It's a security approach.
And how to return back to such menu after users exit the application ?

Thanks!
2 REPLIES 2
Stuart Browne
Honored Contributor
Solution

Re: How to write a special shell menu ?

In the user's profile (.bashrc or .profile or whatever), put commands similar to these:

display_menu() {
clear
echo "*********************"
echo "1. Run Application"
echo "2. Change Password"
echo "3. Logout"
echo "*********************"
}

#
# this disables the ^C interrupt
#
stty intr undef

display_menu

while read LINE
do
case $LINE in
1) /path/to/application
;;
2) passwd
;;
3) exit
;;
*)
echo "Invalid option. Press enter to return to menu."
read JUNK
;;
esac
display_menu
done

Simply put, this will loop forever, taking a value 1, 2 or 3 followed by an Enter. When the application or password change is complete, it'll clear the screen and re-display the menu.


Of course, you can make it as pretty or ugly as you desire, but that's the basics of it.
One long-haired git at your service...
yyghp
Super Advisor

Re: How to write a special shell menu ?

stty is good ! thanks !