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 Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

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 05:51 AM
Help Help Help in recursion murtaza Shell Programming and Scripting 6 03-29-2007 11:26 AM
about memset fuction ranj@chn High Level Programming 3 01-31-2006 08:59 AM
Get Oracle fuction return value in a variable rahulrathod UNIX for Dummies Questions & Answers 3 04-14-2005 01:50 PM
recursion gsjf Shell Programming and Scripting 1 08-26-2002 01:22 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-08-2008
varungupta varungupta is offline
Registered User
  
 

Join Date: Feb 2007
Location: Pune, Dehradun (INDIA), Michigan(US)
Posts: 206
Exclamation awk and fuction (recursion) !! Urgent !!

Hey all,

Could you please check following way of writing awk is correct or not ???

-----------------------------------------------------------

Quote:
pattern= "mqsi[admtspr]"

cat tempgrep.txt | \
while read ppid
do
awk '{
recurcive_fun(ppid, pattern)
function recurcive_fun(n, pattern)
{
awk '{ if ($2~n && $1~pattern){
n=$3
recurcive_fun(n, pattern)}
else{
if ($2~n && $1!~pattern){
print $1 >> "tempmail.txt"
break
}
else {next}
}
}' tempfind.txt
}
}'
done
-----------------------------------------------------------------

Its recursion being called.

tempgrep.txt has :
462948
1311040
880922

tempfind.txt has :
t2589vg 880922 462948 09:57:07 -ksh
mqsiadm 1298856 1311040 09:57:56 -ksh
mqsiadm 1311040 880922 09:57:19 -ksh

Please suggust/correct the script(if wrong) !!
Thanks
Varun

Last edited by varungupta; 02-08-2008 at 03:39 PM..
  #2 (permalink)  
Old 02-08-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,776
awk does not know about pattern:
awk -v pattern=$pattern"

Use the -v option. Plus pattern is misspelled as "pettern".

Please use code tags when you post code.
  #3 (permalink)  
Old 02-08-2008
varungupta varungupta is offline
Registered User
  
 

Join Date: Feb 2007
Location: Pune, Dehradun (INDIA), Michigan(US)
Posts: 206
Thumbs up

Quote:
Originally Posted by jim mcnamara View Post
awk does not know about pattern:
awk -v pattern=$pattern"

Use the -v option. Plus pattern is misspelled as "pettern".

Please use code tags when you post code.
hey,

Thanks for reply

Could you please tell me where i should mention -v option in awk, as awk is used twice in the code ? Now, how my script should look like ?
Thanks, I did notice the typo error for pattern. Thanks anyways.
And when i was running the above script then it given me error saying:Syntax error at line 11 : `(' is not expected.

Please tell me.

Last edited by varungupta; 02-08-2008 at 03:25 PM..
  #4 (permalink)  
Old 02-12-2008
varungupta varungupta is offline
Registered User
  
 

Join Date: Feb 2007
Location: Pune, Dehradun (INDIA), Michigan(US)
Posts: 206
Exclamation

Quote:
#SCRIPT TO CHECK WHO HAS ACCESSED THE LOG/FILE IN PAST 'N' MINUTES, AND MAIL ACCORDINGLY.

MYPATH="/clocal/mqbrkrs/user/mqsiadm/sanjay/"
MAIL_RECIPIENTS="vgabc@def.com"
#maillist"

Subject=":: File(s) accessed/touched in 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

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** " ;
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
# awk '{ if($2~ppid && $1!~pattern) print $1 >> "tempmail.txt" }' tempfind.txt
\`awk 'BEGIN{ pattern = "mqsi[admtsprd]" }
{if ( ppid !~ "" ) { fun( ppid, pattern ); } }

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\`
}
'\`

done

let "index+=1" ;
fi


if [ "$pid_var" -ne "$pidprev" ] ; then
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
# awk '{ if($2~ppid && $1~pattern) print $1 >> "tempmail.txt" }' tempfind.txt
\`awk 'BEGIN{ pattern = "mqsi[admtsprd]" }
{if ( ppid !~ "" ) { fun( ppid, pattern ); } }

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\`
}
'\`
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
---------------------------------------------------------

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.

Last edited by varungupta; 02-14-2008 at 05:10 PM..
  #5 (permalink)  
Old 02-14-2008
varungupta varungupta is offline
Registered User
  
 

Join Date: Feb 2007
Location: Pune, Dehradun (INDIA), Michigan(US)
Posts: 206
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.
Hey,
Unix Gurus...Could you all please give me the solution to this script?
  #6 (permalink)  
Old 02-22-2008
varungupta varungupta is offline
Registered User
  
 

Join Date: Feb 2007
Location: Pune, Dehradun (INDIA), Michigan(US)
Posts: 206
Question

Hey,

I have a dummy script that is the base for the above script where I am getting the problem of syntax.
Dummy script is working fine and is given below, but i dont know why the actual script is not working :

-------------------------------------------------------------------
for var in 1 2
do

echo "var : $var"

count=0
while [ "$count" -lt 3 ]
do
echo "count : $count"

awk 'BEGIN { i = 0
f(i)
}
function f(para)
{
if ( para < 10 )
{
print "\n value of para : " para ;
para += 1 ;
f(para) ;
}
else
{
print "\n inside else, before increment, para : " para ;
para += 1 ;
print "\n inside else, para : " para ;
exit ;
}
}
'
let "count += 1"
done
done

-------------------------------------------------------------------

Please have a look and suggest any solution to the problem.
Thanks to all the unix bonds.

Varun Gupta.
  #7 (permalink)  
Old 03-13-2008
varungupta varungupta is offline
Registered User
  
 

Join Date: Feb 2007
Location: Pune, Dehradun (INDIA), Michigan(US)
Posts: 206
Lightbulb

Quote:
Originally Posted by varungupta View Post
Hey,

I have a dummy script that is the base for the above script where I am getting the problem of syntax.
Dummy script is working fine and is given below, but i dont know why the actual script is not working :

-------------------------------------------------------------------
for var in 1 2
do

echo "var : $var"

count=0
while [ "$count" -lt 3 ]
do
echo "count : $count"

awk 'BEGIN { i = 0
f(i)
}
function f(para)
{
if ( para < 10 )
{
print "\n value of para : " para ;
para += 1 ;
f(para) ;
}
else
{
print "\n inside else, before increment, para : " para ;
para += 1 ;
print "\n inside else, para : " para ;
exit ;
}
}
'
let "count += 1"
done
done

-------------------------------------------------------------------

Please have a look and suggest any solution to the problem.
Thanks to all the unix bonds.

Varun Gupta.


Please provide some suggestion on this !!
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:16 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0