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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

menu script help

Status
Not open for further replies.

smithia6

Technical User
Aug 28, 2002
35
US
I have created a menu script I have created to update a monitoring screen that is viewed in another office by a team, but I am sure this script can be improved on, as it is a little messy, and I can not get it to correctly exit out if a function is called on and then and incorrect keystroke is pressed, so I have just got the script to exit totally if an incorrect key press is made from an option.

What I have to update is a line like this one:-

allitemsData[0]="|green|1107 - Monitoring of Allitems Loads starts at 1915|"

the 1st part can change and be called cgcData[0] or something of the like, as there are 8 different areas that have to be updated.

Here is the unix shell script below.

#!/bin/ksh

# set system variables

timeNow=$(date +"%H%M")
monitor=/tmp/changemonitor.$$
monitor1=/tmp/changemonitor1.$$
monitor2=/tmp/changemonitor2.$$
monitor3=/tmp/changemonitor3.$$
monitor4=/tmp/changemonitor4.$$
monitor5=/tmp/changemonitor5.$$
workdir=/opt/contents/PEGASYSTEMS/JSCRIPT

# Start of functions

function monitornew
{
cat $jsfile >> $logfile
cat $jsfile > $monitor
cat $monitor | tr -s '|' ' ' > $monitor1
cat $monitor1 | awk '{print $1,$2}' > $monitor
echo ""
echo ""
cat $monitor | awk '{print $2}' > $monitor1
cat $monitor | awk '{print $1}' > $monitor2
tr = '\t' < $monitor2 | awk '{print $1}' > $monitor
cat $monitor > $monitor3
tr Data[0] '\t' < $monitor3 | awk '{print $1}' > $monitor4
cat $jsfile > $monitor3
cat $monitor3 | cut -d '|' -f3 > $monitor5
monitor1=$(more $monitor1)
monitor=$(more $monitor)
monitor4=$(more $monitor4)
monitor5=$(more $monitor5)
echo &quot;\\t The colour status of the monitoring screen $monitor4 at the moment is $monitor1 &quot;
echo &quot;\\t The last timestamp and message is $monitor5 &quot;
echo &quot;&quot;
echo &quot;\\t Please select an option you wish to change the monitor screen colour to ...&quot;
echo &quot;\\t \\t r - red&quot;
echo &quot;\\t \\t a - amber&quot;
echo &quot;\\t \\t g - green&quot;
echo &quot;\\t \\t q - quit&quot;
echo &quot;&quot;
echo &quot;\\t Type your option here: \\c&quot;
read colour
case $colour in
r) colour=red ;;
a) colour=amber ;;
g) colour=green ;;
q) echo &quot;&quot;; echo &quot;\\t \\t Quitting the update monitoring screen menu program ....&quot; ; echo &quot;&quot; ; exit 0;;
*) echo \\t \\t \\t \\t That was not a valid option; exit 0;;
esac
echo &quot;&quot;
echo &quot;\\t Please type in the popup message you wish to appear when clicked&quot;
echo &quot;&quot;
echo &quot;\\t Type your message here: \\c&quot;
read popup
echo &quot;&quot;
echo &quot;\\t The monitoring screen has now changed the following information is now being displayed ...&quot;
echo &quot;&quot;
echo &quot;\\t The screen is now $colour and has the message $popup time stamped at $timeNow&quot;
echo &quot;$monitor=\&quot;|$colour|$timeNow - $popup|\&quot;&quot; > $jsfile
echo &quot;&quot;
echo &quot;\\t Hit Return to go back to the main menu&quot;
read
rm /tmp/changemonitor*
}
# End of functions

# Main Menu

clear
echo &quot;\\t \\t a - Update the Allitems Screen&quot;
echo &quot;\\t \\t b - Update the Dishonour Screen&quot;
echo &quot;\\t \\t c - Update the Bulkstore Screen&quot;
echo &quot;\\t \\t d - Update the Exceptions Screen&quot;
echo &quot;\\t \\t e - Update the CGC Screen&quot;
echo &quot;\\t \\t f - Update the Verifications Screen&quot;
echo &quot;\\t \\t g - Update the Conformation File Screen&quot;
echo &quot;\\t \\t h - Update the Verifications Failure File Screen&quot;
echo &quot;\\t \\t i - About This Pega Tool&quot;
echo &quot;\\t \\t q - Quit&quot;
echo &quot;&quot;
echo &quot;\\t \\t Select an option \\c&quot;
read ans
clear
case $ans in
a) jsfile=$workdir/monitorAllitems.js
logfile=$workdir/monitorAllitems.log
monitornew
$0;;
b) jsfile=$workdir/monitorDishonour.js
logfile=$workdir/monitorDishonour.log
monitornew
$0;;
c) jsfile=$workdir/monitorBulkstore.js
logfile=$workdir/monitorBulkstore.log
monitornew
$0;;
d) jsfile=$workdir/monitorExceptions.js
logfile=$workdir/monitorExceptions.log
monitornew
$0;;
e) jsfile=$workdir/monitorCGC.js
logfile=$workdir/monitorCGC.log
monitornew
$0;;
f) jsfile=$workdir/monitorVerifications.js
logfile=$workdir/monitorVerifications.log
monitornew
$0;;
g) jsfile=$workdir/monitorConfirmation.js
logfile=$workdir/monitorConfirmation.log
monitornew
$0;;
h) jsfile=$workdir/monitorVfail.js
logfile=$workdir/monitorVfail.log
monitornew
$0;;
q) echo &quot;&quot;; echo &quot;\\t \\t Quitting the update monitoring screen menu program ....&quot; ; echo &quot;&quot; ; exit 0;;
*) echo \\t \\t \\t \\t That was not a valid option; $0;;
esac


Does anyone have any ideas??

Regards

Ian
 
Smithia6

Don't know if this is what you were looking for but...
I just looked at the part of the function where the user is chosing a colour for the monitor screen..

To exit a just a function and not the script that called the function use return instead of exit.

if you want to keep requesting a correct value in your script until you receive
a valid value or untill the user quits, this might work...

typeset -i CNT
CNT=0
CHOICE='INVALID'
read colour
while [[ $CHOICE != 'VALID' ]] do
CHOICE='VALID'
case $colour in
r)colour=red ;;
a) colour=amber ;;
g) colour=green ;;
q) echo &quot;&quot;; echo &quot;\\t \\t Quitting the update monitoring screen menu program...&quot; ; echo &quot;&quot; ; exit 0;;
*) echo \\t \\t \\t \\t That was not a valid option; CHOICE='INVALID';
read colour;;
esac
(( CNT = CNT + 1 ))
if (( CNT > 10 ))then
echo 'Are you Confused?'
CHOICE='VALID' fi
done
JRjr
 
I have tried that and changed a lot of the script. It works OK but when I add the above code I get syntax errors.

here is the function with the added code from above:-

function monitornew
{
echo &quot;&quot;
cat $jsfile >> $logfile
app=$(cat $jsfile | tr -s 'D' '\t' | awk '{print $1}')
monitorcolour=$(cat $jsfile | cut -d &quot;|&quot; -f2)
message=$(cat $jsfile | cut -d &quot;|&quot; -f3)
echo &quot;\\t The colour status of the monitoring screen $app at the moment is $monitorcolour &quot;
echo &quot;\\t The last timestamp and message is $message &quot;
echo &quot;&quot;
echo &quot;\\t Please select an option you wish to change the monitor screen colour to ...&quot;
echo &quot;\\t \\t r - red&quot;
echo &quot;\\t \\t a - amber&quot;
echo &quot;\\t \\t g - green&quot;
echo &quot;\\t \\t q - quit&quot;
echo &quot;&quot;
echo &quot;\\t Type your option here: \\c&quot;
typeset -i CNT
CNT=0
CHOICE='INVALID'
read usercolour
while [[ $CHOICE != 'VALID' ]] do
CHOICE='VALID'
case $usercolour in
r) usercolour=red ;;
a) usercolour=amber ;;
g) usercolour=green ;;
q) echo &quot;&quot;; echo &quot;\\t \\t Quitting the update monitoring screen menu program...&quot; ; echo &quot;&quot; ; exit 0;;
*) echo \\t \\t \\t \\t That was not a valid option; CHOICE='INVALID';
read usercolour;;
esac
(( CNT = CNT + 1 ))
if
(( CNT > 10 ))
then
echo 'Are you Confused?'
CHOICE='VALID'
fi
done

echo &quot;&quot;
echo &quot;\\t Please type in the popup message you wish to appear when clicked&quot;
echo &quot;&quot;
echo &quot;\\t Type your message here: \\c&quot;
read popup
timeNow=$(date +&quot;%H%M&quot;)
echo &quot;&quot;
echo &quot;\\t The monitoring screen has now changed the following information is now being displayed ...&quot;
echo &quot;&quot;
echo &quot;\\t The screen is now $usercolour and has the message $popup time stamped at $timeNow&quot;
app=$(cat $jsfile | tr -s 'D' '\t' | awk '{print $1}' |sed 's/$/Data/')
echo &quot;$app[0]=\&quot;|$usercolour|$timeNow - $popup|\&quot;&quot; > $jsfile
echo &quot;&quot;
echo &quot;\\t Hit Return to go back to the main menu&quot;
read
}


Where am I going wrong ????

Regards

Ian
 
I just ran your copy of the monitornew function with the main section of your script from above. I did not receive ANY syntax errors. I can't tell what is causing your syntax errors.

JRjr

 
Sorry,

It was my mistake, It was not this function at fault.
Just gave myself a big kick, thanks for looking at my problem, and helping me solve it.

Works a treat.

Regards

Ian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top