Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating shell menus

Status
Not open for further replies.

bigmansmac

Programmer
Aug 15, 2001
12
0
0
GB
I want to create a menu to allow a specific user to perform 2 or 3 tasks only.This is to allow the user to do some system confidence checks but without having to give authority to allow smit access etc.
something along the lines of;

1. check printers
2. check user count
3. exit

Can someone post an example or point me in the direction of any good sites.

Thanks for your time
 
Hi there,

Which part of the task are you unsure about? Is it the generation of the menu or what commands to run to display the results? (It's ok to say "both" by the way :)) Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Hi Mike,

Thanks for the reply.
I am fine with the commands, I want the user to to be presented with a menu when he signs on.
Its so i can restrict the user to these commands only.

Regards

BM
 
BM - this should get you started, it's a bash script (a linux shell) but should be fairly compatible with ordinary sh.

Save everything between the ------ lines into a file named menu.sh

Replace the first line with the path to your sh command.

run the command 'chmod +x menu.sh'

create a couple of scripts called script_to_check_printers.sh and script_to_check_printers.sh to do the checks you want

make those scripts executable with the chmod command (as above)

put all three scripts somewhere on your path

------
#!/bin/sh

while true
do

clear # clear the screen
echo;echo;echo
echo ' Menu'
echo;echo;echo
echo '1 - Check printers'
echo '2 - Check user count'
echo 'X - Exit'
echo
echo 'Enter option required'

read a


if [[ $a -eq '1' ]]
then
script_to_check_printers.sh
fi

if [[ $a -eq '2' ]]
then
script_to_check_users.sh
fi

if [ $a == 'x' ]
then
exit
fi
if [ $a == 'X' ]
then
exit
fi

done
------ Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
BM,
I would call your script at the bottom of the users .profile and make sure when exiting the script to log the user out of the system. Making sure that if they <Ctrl-c> out of the script it will not give them command line access.
Octar
 
There are a number of good books on shell programming; my preference is the korn shell, but to each their own.

I would use a `case` statement instead of a number of `if` statements.

Something similar to the following:

#!/bin/ksh

__funcCheckPrinters()
{
print &quot;checking printers&quot;
exit 0
}

__funcCheckUserCount()
{
print &quot;checking user count&quot;
exit 0
}

print &quot;Enter your selection: &quot;
PS3='selection?'
select ans in 'Check printers' 'Check user count' 'Exit'
do
case $REPLY in
1) __funcCheckPrinters;;
2) __funcCheckUserCount;;
3) exit 0;;
esac
done
 
I implemented my &quot;restricted interface&quot; with a custom-compiled version of Lynx (to allow locally executed scripts). It's implemented as their logon shell, so people stuck it in cannot get to a command line at all. That, combined with sudo makes it possible for me to give root-level tasks to people without them having *any* other access.

The advantage using Lynx has over shell scripting is that I don't have to worry about presentation. Will everything fit without scrolling? What size display (not everyone is 80x25)? Do I have to adjust line justification when I edit what's on the menu? The menu system doesn't have to validate input, and so on.
 
The AIX built-in method would be to use /usr/bin/Rsh as your shell. This is the restricted shell and I leave it up to you to read the man pages, but it should do exacly what you want including preventing escape to a prompt. IBM Certified -- AIX 4.3 Obfuscation
 
To help with security you could have your menu program as the shell. This will help to protect from control C, etc.
ie from /etc/passwd
someuser:!:215:200:Menu User:/home/menuuser:/usr/bin/menu.sh

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top