awk and fuction (recursion) !! Urgent !!


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users awk and fuction (recursion) !! Urgent !!
# 1  
Old 02-08-2008
Error awk and fuction (recursion) !! Urgent !!

Hey all,
Smilie
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
VarunSmilie

Last edited by varungupta; 02-08-2008 at 03:39 PM..
# 2  
Old 02-08-2008
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  
Old 02-08-2008
MySQL

Quote:
Originally Posted by jim mcnamara
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 Smilie

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

Last edited by varungupta; 02-08-2008 at 03:25 PM..
# 4  
Old 02-12-2008
Error

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  
Old 02-14-2008
Quote:
Originally Posted by varungupta
---------------------------------------------------------

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?Smilie
# 6  
Old 02-22-2008
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.Smilie
# 7  
Old 03-13-2008
Lightbulb

Quote:
Originally Posted by varungupta
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.Smilie


Please provide some suggestion on this !!
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl system fuction with

Hi, I've written a perl script with a nested foreach statement in it. I have the line code: foreach $argn(@arguments) { foreach $location (@path) { system("find $location -name \"$argn\" -print >> results.txt"); ... (2 Replies)
Discussion started by: tchoruma
2 Replies

2. Shell Programming and Scripting

Urgent awk help !!

Hi All,I need to convert following field from a file L2578978CLC/576/116804 => L2578978CLC/00000576/00168304 i have to append Zeros in the third and fourth number after slash / in the above string (total length of number should be 8). means L2578978CLC/576/116804 should be converted to... (3 Replies)
Discussion started by: unknown123
3 Replies

3. Shell Programming and Scripting

urgent help awk script

Hi I have a scenario where i have a file name as abcd_To_hfgh.20090456778_1.dat I will get the filename as parameter and i need a string in between second _ and first . i.e i need hfgh in this case. Please help me with the script. This may not be awk script even if it can be... (2 Replies)
Discussion started by: dsdev_123
2 Replies

4. Shell Programming and Scripting

fuction return in perl

Hi All, I have a perl script(1.pl) that calls a c function defined in another file sample.c #!/usr/bin/perl my $re = 1; my @s = `/home/PERL_SCRIPTING/Rough/sample pline $re 10`; print "$_" foreach(@s); The sample.c is as bwlow: # include <stdio.h> int pline(int, int);... (4 Replies)
Discussion started by: jisha
4 Replies

5. UNIX for Dummies Questions & Answers

awk help urgent

Hi i am trying to read a line from a file and add the values in a new file eg Input file a1|a2|a3|a4|a5|a6 b1|b2|b3|b4|b5|b6 c1|c2|c3|c4|c5|c6 expected output File one a1|a2|a3 b1|b2|b3 c1|c2|c3 (3 Replies)
Discussion started by: rysh
3 Replies

6. Shell Programming and Scripting

Urgent!!!!! AWK

Thank everyone advanced. Would you please tell me how to use the shell variable in the awk body? I try follows but they all do not work, pls kindly help me: 1. str=`cat file2` awk 'BEGIN{print("'"$str"'"}' file1 > file3 2. str=`cat file2` awk 'BEGIN{print(ENVIRON}' file1 > file3 3.... (3 Replies)
Discussion started by: summer_cherry
3 Replies

7. Shell Programming and Scripting

Help me for AWK URGENT

i have a record like 1,23423,4545,6767,89898,3434,121212,123123,322 2,23233,3434,4545,56566,rxrx,e344343,343434,3434 1,23223,336,78787,78787,654,6767677,6877989,7878 i want to check the $6 field if its start with any letters, i want to move this record to some other file and keep rest of... (2 Replies)
Discussion started by: readycpbala
2 Replies

8. Programming

about memset fuction

Dear all, In my code,i am planning to use memset function to re-initialise an array before populating it everytime. Will using memset function be an overload to the program? (3 Replies)
Discussion started by: ranj@chn
3 Replies

9. UNIX for Dummies Questions & Answers

Get Oracle fuction return value in a variable

Hi All, :confused: I have the following code. var=' ' sqlplus user/pass@DB <<EOF whenever sqlerror exit 1 select package.func() into $var from dual; EOF echo $var But, this code does not work to display the value returned by the oracle function. Do we have to bind variables before... (3 Replies)
Discussion started by: rahulrathod
3 Replies
Login or Register to Ask a Question