The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
Google UNIX.COM


UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
fuction return in perl jisha Shell Programming and Scripting 4 05-15-2008 01:51 AM
Help Help Help in recursion murtaza Shell Programming and Scripting 6 03-29-2007 07:26 AM
about memset fuction ranj@chn High Level Programming 3 01-31-2006 05:59 AM
Get Oracle fuction return value in a variable rahulrathod UNIX for Dummies Questions & Answers 3 04-14-2005 09:50 AM
recursion gsjf Shell Programming and Scripting 1 08-25-2002 09:22 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #8  
Old 03-25-2008
Registered User
 

Join Date: Feb 2007
Location: Pune, Dehradun (INDIA), Michigan(US)
Posts: 187
Quote:
Originally Posted by varungupta View Post
---------------------------------------------------------

I AM GETTING ERROR :
AccessLogMonitorAdv_script[32]: 0403-057 Syntax error at line 57 : `(' is not expected.

THEN NAME OF MY SCRIPT IS AccessLogMonitorAdv_script

PLEASE SUGGEST SOLUTION TO THIS !!
THANKS
Varun.
----------------------------------------------------------------------------

Have a look to the Syntax of the script and its giving error inside the function "fun" while redirecting the output to the file. ">>"

PLEASE FIND THE CODE ..
Code:
SCRIPT TO CHECK WHO HAS ACCESSED THE LOG/FILE IN PAST 'N' MINUTES, AND MAIL ACCORDINGLY.

MYPATH="/clocal/mqbrkrs/user/mqsiadm/varun/"
MAIL_RECIPIENTS="vg@dc.com"
#

Subject=":: LOGS BEING TOUCHED IN THE LAST FEW MINUTES ::"
>tempmail.txt
>tempfind.txt
>filterfile.txt
>tempgrep.txt
#*******************************************************************
## List all the files which one accessed since last 1 min #####
#*******************************************************************

index=1
pidprev=0

ps -ef | grep "\-ksh" | awk '$8 !~ /grep/ { printf "%s %s %s %s %s\n", $1, $2, $3, $5, $8 ; }' >> ./tempfind.txt

for file_dir in `find $MYPATH -amin -1`
do

        echo `fuser -uf "$file_dir" ` >> temp.txt.$$
        echo " $file_dir is  being accessed" >> temp.txt.$$
done

sed -n '/^[ ][a-z]*/p' temp.txt.$$ >> tempmail.txt
echo "Accessed By: " >>tempmail.txt
sed -n '/^[0-9]/p' temp.txt.$$ > filterfile.txt

echo "BEFORE FOR LOOP"
for pid_var in `awk '{ print $1 }' filterfile.txt`
do
                echo "**here i am inside the for loop** ";

                if [ "$index" -eq 1 ] ; then
                        echo "**inside if 1. ** " ;
                        pidprev="$pid_var" ;
                        echo "pid_var: $pid_var" ;
                        echo "pidprav: $pidprev" ;

                        `awk '$2 ~ pid_var {print $3 > "tempgrep.txt" }' tempfind.txt` ;

                        echo "1. " ;
                        cat tempgrep.txt ;
                        echo "----" ;

                        cat tempgrep.txt | \
                        while read ppid
                        do
                                        echo "**inside while loop 1.**"
                                        `awk 'function fun( n, pattern )
                                               {
                                                `awk '{ if($2~n && $1~pattern){
                                                                n=$3;
                                                                fun( n, pattern ); }
                                                        else{
                                                                if($2~n && $1!~pattern){
                                                                        print $1 >> "tempmail.txt" ;
                                                                        break ;
                                                                        }
                                                                else {next ;}
                                                            }
                                                        }' tempfind.txt`
                                               }

                                              BEGIN{ pattern = "mqsi[admtsprd]" }
                                              {if ( ppid !~ "" ) { fun( ppid, pattern ); }}

                                         '`
                        done

                        let "index+=1"  ;
                fi


                if [ "$pid_var" -ne "$pidprev" ] ; then
                        echo "**inside if 2. ** " ;
                        pidprev="$pid_var" ;
                        echo "pid_var: $pid_var" ;
                        echo "pidprav: $pidprev" ;
                       `awk '$2 ~ pid_var {print $3 > "tempgrep.txt" }' tempfind.txt` ;

                        echo "2. ";
                        cat tempgrep.txt ;
                        echo "----" ;

                        cat tempgrep.txt | \
                        while read ppid
                        do
                                echo "***inside while loop 2. ***"
                                        `awk 'function fun( n, pattern )
                                               {
                                                `awk '{ if($2~n && $1~pattern){
                                                                n=$3;
                                                                fun( n, pattern ); }
                                                        else{
                                                                if($2~n && $1!~pattern){
                                                                        print $1 >> "tempmail.txt" ;
                                                                        break ;
                                                                        }
                                                                else {next ;}
                                                            }
                                                        }' tempfind.txt`
                                               }

                                              BEGIN{ pattern = "mqsi[admtsprd]" }
                                              {if ( ppid !~ "" ) { fun( ppid, pattern ); }}

                                         '`
                        done
                fi

done

cat tempmail.txt | mailx -s "$Subject" "$MAIL_RECIPIENTS"

rm -f "temp.txt.*" 2> /dev/null
# >tempmail.txt
# >tempfind.txt
# >filterfile.txt
# >tempgrep.txt

Do let me know the suggestions !!
Thanks
Varun.
Reply With Quote
Forum Sponsor
  #9  
Old 03-25-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
Quote:
Originally Posted by varungupta View Post
Code:
                                echo "***inside while loop 2. ***"
                                        `awk 'function fun( n, pattern )
                                               {
                                                `awk '{ if($2~n && $1~pattern){
You can't nest backticks like that. However, there's an alternate syntax which works.

Code:
var=$(echo outer and $(echo inner) backticks, oh my)
You would be more likely to get useful replies if you pared down the question to just the specific problem you have, rather than post an enormous script.
Reply With Quote
  #10  
Old 03-25-2008
Registered User
 

Join Date: Feb 2007
Location: Pune, Dehradun (INDIA), Michigan(US)
Posts: 187
Quote:
Originally Posted by era View Post
You can't nest backticks like that. However, there's an alternate syntax which works.

Code:
var=$(echo outer and $(echo inner) backticks, oh my)
You would be more likely to get useful replies if you pared down the question to just the specific problem you have, rather than post an enormous script.
Hey,
Thanks for suggestions.
Can you tell me how to resolve that backticks in my code ?
As per my code, i am using awk, and how to resolve that nested feature ?
Please let me know, appreciate all your help.

Varun.
Reply With Quote
  #11  
Old 03-26-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
Hint: I wrote "there is an alternative syntax which works". Try it.
Reply With Quote
  #12  
Old 03-31-2008
Bala24's Avatar
Registered User
 

Join Date: Mar 2008
Location: Chennai, India
Posts: 1
Hey Varun,

Did you got what you wanted or still looking for the solution..
Reply With Quote
  #13  
Old 04-16-2008
Registered User
 

Join Date: Feb 2007
Location: Pune, Dehradun (INDIA), Michigan(US)
Posts: 187
Quote:
Originally Posted by Bala24 View Post
Hey Varun,

Did you got what you wanted or still looking for the solution..
Hey,

Hope i'll give you good news soon, as far as this script is concerned !!

Thanks for being active and joining the forum for this issue.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 09:23 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0