Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 06 Jan 1996 13:27:57 -0800 (PST)
From:      JOHN <JSINNOTT@POMONA.EDU>
To:        freebsd-chat@freebsd.org
Subject:   Request for comments on shell script!
Message-ID:  <01HZOWRLI2MQ8WX3K4@POMONA.EDU>

next in thread | raw e-mail | index | archive | help

I hope this isn't an inappropriate forum for this..  Basically, I wrote a bash
shell script to provide menu functions to users unfamiliar with Unix.  I am
going to run this script in the place of a true command shell.  But I do
provide for the user to start a shell if he or she wants to.  This is nothing
fancy, and I am SURE there are more elegant ways to do this, but except for a
few things, this works so far for me.  I did look into the mshell by the way.

Anyway - my problem is, I wrote this in such a way that I believe every time a
user goes to a sub menu (mail.menu for instance) and then returns to the
main.menu, a new process is spawned.  I think this because if I run the script
as a shell, and go to different menus, and then use the [B]ye! command to
logout, it returns back to the main menu AS MANY TIMES AS I HAVE GONE TO A SUB
MENU AND BACK.  After that number of times, it finally logs out.

So, if anyone has any suggestions as to how I can solve this problem, I would
appreciate it.
Also, any comments on possible security problems, as well as any pointers to
programming would also be welcome.
I am VERY new to programming and even newer to FreeBSD, so please be patient
with it.  :)

Thanks a lot!
John


PS - the main.menu, which is where the user is first placed, is the last
function defined, with the sub menus defined before it.

Script follows:



#!/usr/local/bin/bash

PATH=$HOME/bin:/bin:/usr/bin:/usr/local/bin
export PATH
EDITOR=vi
export EDITOR
PAGER=less
export PAGER
umask 2

function mail.menu
{
clear
echo "	 	       `date`"
echo ""
echo " 			         Mail Menu				"
echo "			         ^^^^^^^^^				"
echo ""
echo ""
echo "	 [P]ine				Easy to use pine mail client.	"
echo "	 [E]lm				Simple but powerful mail client."
echo "	 [M]ail				Quick mail on command line.      "
echo ""
echo ""
echo ""
echo ""
echo ""
echo "	 [R]eturn			Return to the Main Menu.	"
echo ""
echo ""
echo ""
echo ""
echo ""
echo ""
echo -n "Command> "; read command
case $command in
	P|p) clear
	     pine
	     mail.menu;;
	E|e) clear
	     elm
	     mail.menu;;
	M|m) clear
	     echo "Who would you like to mail?"; read target
	     mail $target
	     mail.menu;;
	R|r) main.menu;;
	  *) echo "Sorry, that is not an acceptable command.  Please try
again."
	     sleep 1
	     mail.menu;;
esac
}

function telnet.menu
{
clear
echo "Please enter the hostname of the site to which you would like to
connect."
echo "Enter in the format \"name.subdomain.domain\" - i.e. anubis.pomona.edu"
echo ""
echo  -n "Hostname> "
read telnet
case `ping -c1 $telnet > /dev/null` in
	0) echo ""
           echo "That host can not be reached at this time. Check to see that"
	   echo "you entered the name correctly.  If you have, either try "
	   echo "specifying the IP address of the host, or try again later."
	   main.menu;;
	*) clear; telnet $telnet;;
esac
}

function ftp.menu
{
clear
echo "Please enter the hostname of the site to which you would like to
connect."
echo "Enter in the format \"name.subdomain.domain\" - i.e. anubis.pomona.edu"
echo ""
echo -n "Hostname> "
read ftp
case `ping -c1 $ftp > /dev/null` in
	0) echo ""
           echo "That host can not be reached at this time. Check to see that"
	   echo "you entered the name correctly.  If you have, either try "
	   echo "specifying the IP address of the host, or try again later."
	   main.menu;;
	*) clear
	   echo "Attempting to connect, program will redial if host is busy"
	   echo "so be patient!"
           echo ""; ncftp -r $ftp;;
esac
}

function phone.menu
{
clear
echo "Please enter the name of the user to which you would like to talk."
echo "If they are on this host, then you may just enter their username, "
echo "otherwise enter their full e-mail address."
echo ""
echo "Enter in the format \"name@subdomain.domain\" - i.e. john@pomona.edu"
echo ""
echo -n "Username> "
read username 
clear
echo "Attempting to connect with the user, wait..."
echo ""; ytalk $username
main.menu
}

function shell.menu
{
clear
echo "	 	       `date`"
echo ""
echo " 			         Shell Menu				"
echo "			         ^^^^^^^^^^				"
echo ""
echo ""
echo "	 [B]ash				GNU Bourne Again SHell.	"
echo "	 [C]sh				The C shell, developed at Berkeley."
echo ""
echo ""
echo ""
echo ""
echo ""
echo ""
echo "	 [R]eturn			Return to the Main Menu.	"
echo ""
echo ""
echo ""
echo ""
echo ""
echo ""
echo  -n "Command> "; read command
case $command in
	B|b) clear
	     bash
	     shell.menu;;
	C|c) clear
	     csh
	     shell.menu;;
	R|r) main.menu;;
	  *) echo "Sorry, that is not an acceptable command.  Please try
again."
	     sleep 1
	     shell.menu;;
esac
}

function finger.menu
{
clear
echo "Who would you like to check up on?  Please enter the full e-mail"
echo "address of the user, if they are on a remote host."
echo ""
echo ""
echo -n "User> "
read user
clear
finger $user
sleep 4
info.menu
}

function whois.menu
{
clear
echo "Please enter the key words you think might identify the host you"
echo "are looking up.  For instance, to look up DNS names for UCLA,"
echo "you might enter University California Los Angeles - simple!"
echo ""
echo "The information that the Whois search returns will be fed into"
echo "the viewing utility, \"less\".  If the output is short, you won't"
echo "really need it, but if it is long, it might be helpful.  To move"
echo "down a line in \"less\", type RETURN and type SPACE to go down"
echo "a page at a time.  To move back one page, type \"b\"."
echo ""
echo ""
echo -n "Please enter your key words> "
read whois
clear
whois $whois | less
info.menu
}

function info.menu
{
clear
echo "	 	       `date`"
echo ""
echo " 			         Info Menu				"
echo "			         ^^^^^^^^^				"
echo ""
echo ""
echo "	 [F]inger			Check up on another user.	"
echo "	 [W]hois			Look up information on other hosts."
echo "	 [A]rchie			Not implemented at this time.      "
echo ""
echo "   (More items to be added later.)"
echo ""
echo ""
echo ""
echo ""
echo "	 [R]eturn			Return to the Main Menu.	"
echo ""
echo ""
echo ""
echo ""
echo ""
echo ""
echo -n "Command> "; read command
case $command in
	F|f) finger.menu;;
	W|w) whois.menu;;
	A|a) clear
	     echo "Unimplemented at this time - check back later!"
	     sleep 1
	     info.menu;;
	R|r) main.menu;;
	  *) echo "Sorry, that is not an acceptable command.  Please try
again."
	     sleep 1
	     info.menu;;
esac
}

function main.menu
{
clear
echo "		           Welcome to `hostname -s`, $LOGNAME!		"
echo "		         `date`					        "
echo ""
echo "		   	       ANUBIS MAIN MENU				"
echo ""
echo "	[M]ail                         Send, receive, and reply to e-mail."
echo "	[N]ews                         Post, read, and reply to Usenet News."
echo "	[W]eb                          Use the text mode WWW browser, Lynx."
echo "	[T]elnet                       Telnet to another host."
echo "	[F]TP                          Transfer files to and from another
host."
echo "	[P]hone                        Talk to a user on this or another host."
echo "	[S]hell                        Run the Bash or Csh Unix Shell
programs."
echo ""
echo "	[I]nfo                         Finger, Whois, Archie, etc."
echo "	[C]omments                     Send mail to the system operator."
echo "	[L]ook			       Look to see who is on this system."
echo ""
echo "	[B]ye!                         Logout out of this system."
echo ""
echo ""
echo ""
echo -n "Command> "; read command
case $command in
	M|m) mail.menu
	     main.menu;;
	N|n) clear
	     rtin
	     main.menu;;
	W|w) clear
	     lynx
	     main.menu;;
	T|t) telnet.menu
	     main.menu;;
	F|f) ftp.menu
	     main.menu;;
	P|p) phone.menu
	     main.menu;;
	S|s) shell.menu
	     main.menu;;
	I|i) info.menu
	     main.menu;;
	C|c) clear
	     echo "Enter your subject, type what you want, and then type a
period and enter on an  empty line to send the message.  I'll get back to you
as soon as possible."
	     echo "Thanks."
	     echo ""
	     mail root
	     main.menu;;
	L|l) clear
	     who
	     sleep 3
	     main.menu;;
	B|b) clear
	     echo "Thanks for visiting `hostname -s`, $LOGNAME!  Stop by again
soon."
	     sleep 3
	     kill -HUP;;
	  *) clear
	     echo "That is not a valid command.  Please try again."
	     sleep 1
	     main.menu;;
esac
}

main.menu





Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?01HZOWRLI2MQ8WX3K4>