help using read in menu script to cat out lines in logs

What is wrong with my menu script? Do I need to continue with the read statements? All I want to do with option 4 is to cat some /var/log/files and awk out a few lines? How do I do that please?

$ cat menu.sh                                                
#!/bin/bash                                                  
#set -vx                                                     

while :
do     
  clear
  # Display menu
  echo          
  echo  "*************************************************************"
  echo  "Please choose from the following options; type the"           
  echo  "option number and hit the <Enter> key."                       
  echo                                                                 
  echo  "   1) To list names of the log files in the current DIR"          
  echo  "   2) Display today's date and time"                          
  echo  "   3) Display a sorted list of people currently logged on"    
  echo  "   4) Display whether a file is a file or a DIR"              
  echo  "   5) Create a backup for a file"                             
  echo  "   6) Find a user by First of Last name in /etc/passwd file"  
  echo  "   7) Find the manual pages for a specific command"           
  echo  "   8) Exit"                                                   
  echo                                                                 
  echo  "*************************************************************"
  read option                                                          
  case "$option" in                                                    
      1)    echo "The files in the current DIR are: "                  
            ls -al                                                      
            echo "Hit <Enter> to continue."                            
            read ignore                                                
            ;;                                                         
      2)    echo "The current date is: "                               
            date                                                       
            unset date                                                 
            echo "Hit <Enter> to continue."                            
            read ignore                                                
            ;;    

At this point, I'd like to change the menu to do this:

echo ---------------------------------
cd /var/log
# /var/log/secure section
cat /var/log/secure |grep -i 'password check failed'|awk '{print $1,$2,$3,$6,$7,
$8,$11}'|sort -u|more
cat /var/log/secure |grep -i 'password check failed'|wc -l |awk '{print $0}'
cat /var/log/secure |grep -i 'sudo'|awk '{print $1,$2,$3,$7,$8,$9,$10}'|sort -u
cat /var/log/secure |grep -i 'sudo'|wc -l |echo sudo used

cat /var/log/secure |grep -i 'su'|awk '{print $1,$2,$3,$5,$7,$8,$11}'|sort -u
cat /var/log/secure |grep -i 'authentication failure'|awk '{print $1,$2,$3,$13}'
|sort -u
cat /var/log/secure |grep -i 'rhost'|sort -u

cat /var/log/secure |grep -i 'could not identify password' |awk '{print $1,$2,$3
,$13}'|sort -u

  esac
done

I want it to cat the files and grep for certain items? Do I need another read statement? What should it be? I'd like to get this done today, as my meeting is in 4 hours. Any help would be appreciated. I tried this and it didn't work:

      4)    echo "Display problems with /var/log/secure and messages"
            # read fdname                                                       
  
            # if [ ! -e $fdname ]; then                                         
  
              # echo "$fdname does not exist."                                  
  
            # elif [ -d $fdname ]; then                                         
  
            #  echo "$fdname is a directory."                                   
 
            # elif [ -f $fdname ]; then                                         
  
             #  echo "$fdname is a regular file."                               
  
            # else                                                              
  
            #   echo "$fdname is something else."                               
  
            # fi                                                                
  
           # echo "Hit <Enter> to continue."                                    
 
           #  read ignore                                                       
  
            # ;;
echo ---------------------------------
cd /var/log
# /var/log/secure section
cat /var/log/secure |grep -i 'password check failed'|awk '{print $1,$2,$3,$6,$7,
$8,$11}'|sort -u|more
cat /var/log/secure |grep -i 'password check failed'|wc -l |awk '{print $0}'
cat /var/log/secure |grep -i 'sudo'|awk '{print $1,$2,$3,$7,$8,$9,$10}'|sort -u
cat /var/log/secure |grep -i 'sudo'|wc -l |echo sudo used

cat /var/log/secure |grep -i 'su'|awk '{print $1,$2,$3,$5,$7,$8,$11}'|sort -u
cat /var/log/secure |grep -i 'authentication failure'|awk '{print $1,$2,$3,$13}'
|sort -u
cat /var/log/secure |grep -i 'rhost'|sort -u

cat /var/log/secure |grep -i 'could not identify password' |awk '{print $1,$2,$3
,$13}'|sort -u

  esac
done
8)    echo "Have a nice day"
            sleep 1.5
            break
            ;;
$

Thanks.

---------- Post updated at 09:23 AM ---------- Previous update was at 09:05 AM ----------

This is what is happening now.

*************************************************************
Please choose from the following options; type the
option number and hit the <Enter> key.

   1) To list names of the log files in the current DIR
   2) Display today's date and time
   3) Display a sorted list of people currently logged on
   4) List the log files in /current_release/logs
   5) Create a backup for a file
   6) Find a user by First of Last name in /etc/passwd file
   7) Find the manual pages for a specific command
   8) Exit

*************************************************************
4
Issues with /var/log/secure
0
Hit <Enter> to continue.

when I choose option 4, it echos but won't cat out the line.

The actual code is below.

  read option                                                          
  case "$option" in                                                    
      1)    echo "The files in the current DIR are: "                  
            ls -al                                                      
            echo "Hit <Enter> to continue."                            
            read ignore                                                
            ;;                                                         
      2)    echo "The current date is: "                               
            date                                                       
            unset date                                                 
            echo "Hit <Enter> to continue."                            
            read ignore                                                
            ;;                                                         
      3)    echo "The following is a list of the users"    
            echo "currently logged in:"                                
            who | cut -d " " -f1 | sort -u                             
            echo "Hit <Enter> to continue."                            
            read ignore                                                
            ;;                                                         
      4)    echo "Issues with /var/log/secure"
            cat /var/log/secure |grep -i 'password check failed'|wc -l |awk '{pr
int $0}'
            echo "Hit <Enter> to continue."                            
             read ignore
            ;;
  esac
done
8)    echo "Thank You for Snas"
            sleep 1.5
            break
            ;;
$
$

To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags

```text
 and 
```

by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums

Actually, why should it? From my understanding,

means "echo the number of lines found in file /var/log/secure containing 'password check failed'" ...!?

Thanks. I did figure that out earlier and work through the issue. You are completely correct, my logic was asking for the number of issues and the number of issues was 0. Thanks for your help.

Did you try to win the Useless Use of Cat Award :cool:

grep -ci "password check failed" /var/log/secure

No, but thanks. I am fairly new at scripting. Like maybe 2 days. :stuck_out_tongue:

---------- Post updated at 02:21 PM ---------- Previous update was at 02:06 PM ----------

Another dumb question. The man pages state:

Two regular expressions may be joined by the infix operator |; the
resulting regular expression matches any string matching either subex-
pression.

I tried several times to grep for multiple items, do you have an e.g.?

[henry@impala ~]$ man grep
[henry@impala ~]$ cat junk.log|grep [hello|this]
grep: Unmatched [ or [^
bash: this]: command not found
[henry@impala ~]$ cat junk.log|grep [hello|;this]
bash: syntax error near unexpected token `;'
[henry@impala ~]$ cat junk.log|grep hello|;this
bash: syntax error near unexpected token `;'
[henry@impala ~]$ man grep
[henry@impala ~]$ cat junk.log|grep hello|this
bash: this: command not found
[henry@impala ~]$ grep -ci "hello|this" junk.log
0
[henry@impala ~]$ grep -ci hello|this junk.log
bash: this: command not found

[henry@impala ~]$ grep -ci hello;this junk.log

bash: this: command not found

cat junk.log | grep '[hello|this]'

So easy and I tried the stupid curly brackets and every combination but the one you showed. Thanks so much.

You just win the Useless Use of Cat Award :wink:

# grep '[hello|this]' junk.log
# grep "hello\|this" junk.log

My script is almost done! Thanks everyone for your help and support.

---------- Post updated at 01:32 PM ---------- Previous update was at 09:49 AM ----------

Sorry, it was working fine. Then my boss had me change the words in the grep from error to failure and now its acting totally bizarre.

[root@current]# grep -i '[exception|fail]' demo-sam*.log|sort -u |more
6161]
2009/266 03:18:13.437: DEBUG snas.sam.MocClientAcceptor-36:processClientRequest(line 1414) - Received obj: DataRequest:13953921
2009/266 03:18:13.438: DEBUG snas.sam.MocClientAcceptor-36:sendObject(line 2226) - !!Transmitted Object Complete {user:mocuser1}: DataRequest:13953921
2009/266 03:18:43.451: DEBUG snas.sam.MocClientAcceptor-36:processClientRequest(line 1414) - Received obj: DataRequest:381753
2009/266 03:18:43.452: DEBUG snas.sam.MocClientAcceptor-36:sendObject(line 2226) - !!Transmitted Object Complete {user:mocuser1}: DataRequest:381753
2009/266 03:19:03.440: DEBUG snas.sam.MocAlertSveAcceptor-7:processMocResponse(line 298) - Received NativeData with key: Nat_ops_0000_207
2009/266 03:19:03.440: DEBUG snas.sam.MocAlertSveAcceptor-7:processMocResponse(line 299) - **** Native Type: Nat_ops_0000_207, Size: 901
2009/266 03:19:03.441: ERROR snas.sam.MocServiceManager:publishNativeData(line 525) - Native Data is not registered. Dropped Nat_ops_0000_207
2009/266 03:19:03.564: DEBUG snas.sam.MocAlertSveAcceptor-7:resetObjOutputStream(line 286) - <Threshold Reset> OutputStream reset - I/O messages: [37700, 1]
2009/266 03:19:04.560: DEBUG snas.sam.MocAlertSveAcceptor-7:processMocResponse(line 298) - Received NativeData with key: Nat_ops_1000_209
2009/266 03:19:04.560: DEBUG snas.sam.MocAlertSveAcceptor-7:processMocResponse(line 299) - **** Native Type: Nat_ops_1000_209, Size: 6963

In what particular way? - I take it that what you posted is the output you're currently getting, but what about the input (read: log file) you're starting from? Could you please show as an excerpt from that as well ...

Did you try:

grep -i "exception\|fail" file