
01-05-2009
|
|
Shell programmer, author
|
|
|
Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,361
|
|
Quote:
Originally Posted by rookieuxixsa
I am trying to set up prompts when you don't enter the right information or dont enter the information at all, when executing a script. Below is the question that i am asking and i am not sure how to set up the if statements to make sure that the user enters the name, cpu's, memory and ip. I was told that getopts with a cease statement might be usefull, but im not sure how to apply it. Any help would be greatly appreciated...
|
Please put code inside [code] tags.
Quote:
Code:
NAME=$1
NCPUS=$2
MEMORY=$3
IP=$4
MACHINENAME=`hostname`
MASTERHOST=svvnyc702
echo "Do you wish to proceed with the creation of UAT ZONE zone-${NAME}, CPU's ${NCPUS}, MEMORY ${MEMORY}, IP ${IP}
<y or n> ? \c"
|
Code:
while [ -z "$name" ] ## I recommend using lowercase variable names
do
printf "Enter NAME: "
read name
done
while [ -z "$ncpus" ]
do
printf "Enter number of CPUs: "
read ncpus
done
while [ -z "$memory" ]
do
printf "Enter memory: "
read memory
done
Quote:
Code:
read WISH
echo
if [ $WISH = "n" ] ; then
echo "You chose no, good bye"
exit
fi
if [ ! $WISH = "y" ] ; then
echo in vaild optin g - exiting
exit
fi
|
Code:
read wish
case $wish in
n) echo "You chose no, good bye"
exit ;;
esac
|