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
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