The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 10-12-2008
ggayathri ggayathri is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 18
Need help with shell script

Hi,

I need a little bit of help with debugging of this script. The purpose of this script is to check if a particular user has logged in. If logged out, then I would like to send an email containing the output of a log to a set of email ids.


Code:
#! /bin/sh                                                                      
                                                                                
echo "The current users are:"                                                   
                                                                                
who | awk '{print $1}' | sort > temp1                                           
cp temp1 temp2                                                                  
more temp1                                                                      
                                                                                
while true                                                                      
do                                                                              
    who | awk '{print $1}' | sort > temp2                                       
    cmp -s temp1 temp2                                                          
                                                                                
    case "$?" in                                                                
                                                                                
    0)                                                                          
        echo "No user has logged in/out in the last 5 seconds."                 
        ;;                                                                      
                                                                                
    1)                                                                          
        user='gayathri'                                                         
        file=`grep $user temp1 temp2 | cut -c 1-5`  
        file=`grep $user temp1 temp2 | cut -c 1-5`                              
                                                                                
        if [ $file = "temp1" ]                                                  
            echo "User "$user" has logged out."                                 
                                                                                
                                                                                
        if [ $file = "temp2" ]                                                  
            echo "User "$user" has logged in."                                  
        ;;                                                                      
                                                                                
    esac                                                                        
                                                                                
    rm temp1                                                                    
    mv temp2 temp1                                                              
                                                                                
done

I get this error:

The current users are:
gayathri
root
./audit5.ss[9]: 0403-057 Syntax error at line 30 : `;' is not expected.


Can anyone tell me what mistake is there please. Any help is appreciated.

Last edited by tayyabq8; 10-13-2008 at 02:17 AM.. Reason: Added code tags