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

Shell Script Error : Menu script

Status
Not open for further replies.

JRMS

MIS
Sep 4, 2003
144
US
I am attempting to create a shell script with the following capaciblities:

1. Listed options to choice from
2. Use to perform awk statements
3. Print a report with the awk results

My questions are

1. How do I select more than one file for option #5 and #6
2. How to I create an output file for each option of 5 and 6
3. Is it better to use case statements, if so why
4. I am receiving the following arrow message on line #21.
'/menu_script.sh: line 21: syntax error near unexpected token `in
'/menu_script.sh: line 21: ` case "$yourch" in

Below is the script:

# Script to create menus and take action according to that selected menu item.
#
#
while :
do
clear
echo "----------------------------------------------"
echo " * * * * * * * Main Menu * * * * * * * * * * "
echo "----------------------------------------------"
echo "[1] Show Today's date/time"
echo "[2] Show files in current directory"
echo "[3] Show calendar"
echo "[4] Start editor to write letters"
echo "[5] Show IP's scanned by Nessus"
echo "[6] Produce a Tabular Nessus Report"
echo "[7] Produce a non-scan Tabular Nessus Report"
echo "[8] Exit/stop"
echo "----------------------------------------------"
echo -n "Enter your menu choice [1-5]:"
read yourch
case $yourch in
1) echo "Today is 'date' , press a key. . ." ; read ;;
2) echo "Files in 'pwd'" ; ls -l ; ech "Press a key. . ." ; read ;;
3) cal ; echo "Press a key. . ." ; read ;;
4) vi ;;
5) echo "Enter your NBE file(s): \c"; read FNAME; cat "$FNAME" | grep results |
awk -F"|" '{print $3}' | sort | uniq ;;
6) echo "Enter your NBE file(s): \c"; read FNAME; cat "$FNAME" |
awk -F"|" '$1 == "results" {gsub (/\n/,"",$7};
printf "%s\t%s\t%s\t%s\t%s\n", $3,$4,$5,$6,$7}' > rawresults.txt
7) echo "Enter your NBE file(s): \c"; read FNAME; cat "$FNAME" | awk -F"|"
'$1 != "results" {gsub (/\n/,"",$7); printf "%s\t%s\t%s\n", $1,$2,$3,&$7} > non_results.txt
8) exit 0 ;;
*) echo "Opps!!! Please select choice 1,2,3,4,5,6,7 or 8";
echo "Press a key. . ." ; read ;;
esac
done
 
Hi

[ol]
[li]Please post your code between [tt][ignore]
Code:
[/ignore][/tt] and [tt][ignore]
[/ignore][/tt] tags.[/li]
[li]Please indent your code.[/li]
[li]Please specify what shell are you using.[/li]
[li]Please check the syntax for typos.[/li]
[/ol]
Code:
while :
do
  clear
  echo "----------------------------------------------
 * * * * * * * Main Menu * * * * * * * * * *
----------------------------------------------
[1] Show Today's date/time
[2] Show files in current directory
[3] Show calendar
[4] Start editor to write letters
[5] Show IP's scanned by Nessus
[6] Produce a Tabular Nessus Report
[7] Produce a non-scan Tabular Nessus Report
[8] Exit/stop
----------------------------------------------"
  echo -n "Enter your menu choice [1-[red]8[/red]]:"
  read yourch
  case $yourch in
    1) echo "Today is [red]`[/red]date[red]`[/red] , press a key. . ." ; read ;;
    2) echo "Files in [red]`[/red]pwd[red]`[/red]" ; ls -l ; echo "Press a key. . ." ; read ;;
    3) cal ; echo "Press a key. . ." ; read ;;
    4) vi ;;
    5) echo "Enter your NBE file(s): \c"; read FNAME; cat "$FNAME" | grep results | awk -F"|" '{print $3}' | sort | uniq ;;
    6) echo "Enter your NBE file(s): \c"; read FNAME; cat "$FNAME" | awk -F"|" '$1 == "results" {gsub (/\n/,"",$7}; printf "%s\t%s\t%s\t%s\t%s\n", $3,$4,$5,$6,$7}' > rawresults.txt [red];;[/red]
    7) echo "Enter your NBE file(s): \c"; read FNAME; cat "$FNAME" | awk -F"|" '$1 != "results" {gsub (/\n/,"",$7); printf "%s\t%s\t%s\n", $1,$2,$3,$7} > non_results.txt [red];;[/red]
    8) exit 0 ;;
    *) echo "Opps!!! Please select choice 1,2,3,4,5,6,7 or 8"; echo "Press a key. . ." ; read ;;
  esac
done
And note that using [tt]read[/tt] and printing "Press a key" is abit misleading.

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top