- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: Sample Shell Script with Menu
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-18-2006 04:44 AM
тАО01-18-2006 04:44 AM
Sample Shell Script with Menu
Ok maybe I am going to be chastised to not doing more research but it never hurts to ask I guess.
I need to make a basic script which when run gives the user a list say of ten things whereby they can select a number and then it performs that operation.
Does anybody know where I could find a template script to kick me off. Say something silly with a few options.
Thanks so much in advance!
Cheers
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-18-2006 04:53 AM
тАО01-18-2006 04:53 AM
Re: Sample Shell Script with Menu
See attached.
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-18-2006 04:57 AM
тАО01-18-2006 04:57 AM
Re: Sample Shell Script with Menu
In lieu of declaring '/usr/bin/sh' in the user's initial program field in '/etc/passwd' substitute your shell (menu) script. Then make the script look something like:
#!/usr/bin/sh
PATH=/usr/sbin:/usr/bin:/sbin
trap '' INT QUIT
while true
do
clear
echo "Host: $(hostname). $(date "+%a %x %X %Z"). [ Operations Utilities ]"
echo "\n >>> Enter < 0 > to Logout"
echo "\n >>> Enter < l > to ..."
echo "\n >>> Enter < 2 > to ..."
echo "\n*---> \c"
read CHOICE
case ${CHOICE} in
0 ) exit 0
;;
1 ) ${HOME}/script/abc
;;
2 ) ${HOME}/script/xyz
;;
"") continue
;;
esac
done
exit
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-18-2006 04:59 AM
тАО01-18-2006 04:59 AM
Re: Sample Shell Script with Menu
I have had a similar question, have a look at this thread, there are a lot of sample scripts
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=984784
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-18-2006 05:27 AM
тАО01-18-2006 05:27 AM
Re: Sample Shell Script with Menu
Rgds...Geoff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-18-2006 06:48 AM
тАО01-18-2006 06:48 AM
Re: Sample Shell Script with Menu
Attached is a template for a menu driven shell script. It can be used as a framework for building upon. Enjoy and hope it helps!!!
:)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-18-2006 07:41 AM
тАО01-18-2006 07:41 AM
Re: Sample Shell Script with Menu
#! /usr/bin/ksh
#
#
clear
writeyx () {
tput cup $2 $3
echo "$1"
}
Starting_messages () {
clear
writeyx "Please, give as many input as posible." 8 20
writeyx "USERNAME=" 10 20
writeyx "EVENTNAME=" 12 20
writeyx "SYSCALL=" 14 20
writeyx "FROM mmddhhmm[yy]" 16 20
writeyx "TO mmddhhmm[yy]=" 18 20
tput smso; writeyx "" 40 0
read user; writeyx "$user" 10 40
tput smso; writeyx "" 40 0
read event; writeyx "$event" 12 40
tput smso; writeyx "" 40 0
read syscall; writeyx "$syscall" 14 40
tput smso; writeyx "" 40 0
read from_date; writeyx "$from_date" 16 40
tput smso; writeyx "" 40 0
read to_date; writeyx "$to_date" 18 40
tput rmso
if [[ $user != "" ]]; then
OPTIONS="-u $user"
fi
if [[ $event != '' ]]; then
OPTIONS="$OPTIONS -e $event "
fi
if [[ $syscall != "" ]]; then
OPTIONS="$OPTIONS -c $syscall"
fi
if [[ $from_date != '' ]]; then
OPTIONS="$OPTIONS -t $from_date "
fi
if [[ $to_date != '' ]]; then
OPTIONS="$OPTIONS -s $to_date "
fi
tput cup 41 6
print -n "Requesting to know if $user ran command that called $syscall btw $FD to $TD"
print -n "Press y/n/q"
read ans
}
from_date () {
dates=$from_date
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-18-2006 09:14 AM
тАО01-18-2006 09:14 AM
Re: Sample Shell Script with Menu
use strict;
use diagnostics;
S_="MENU";
write;
print "Enter Choice:";
my $choice=
if($choice=~/[Aa]) {
print "You picked option A\n";
}elsif{$choice=~/[Ll} {
exit(0);
}
format MENU
============================================
a. do something
b. do something else
l. exit
===========================================
.
Hope this helps
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-15-2007 12:16 PM
тАО05-15-2007 12:16 PM
Re: Sample Shell Script with Menu
echo "\n >>> Enter for the current time"
read choice
case ${choice} in
If the user selects , how would you write this in the script to execute the time command?
Thank all!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-15-2007 02:38 PM
тАО05-15-2007 02:38 PM
Re: Sample Shell Script with Menu
I was going to say you use the select builtin. And if you look at Pete's example, it does that.
>echo ">>> Enter for the current time"
>read choice
>case ${choice} in
One could do that. For my select example:
echo "Select the compare mode:"
select DT in "-r" "-b" "-a"; do
break
done
if [ "$DT" = "" ]; then
DT="-r"
fi
This prints:
Select the compare mode:
1) -r
2) -b
3) -a
#?
The user types in a number, 1 to 3.
The logic above says if an invalid number is typed, set it to the "-r" choice.
>If the user selects , how would you write this in the script to execute the time command?
For your case:
case ${choice} in
"") date ;;
... # other choices
*) echo "invalid choice: ${choice}" ;;
esac
- Tags:
- select