I am new to shell scripting and i am preparing a script.
for now i am work on a sub part of it..but i am unable to make it work.
---
the test code that i am working on
--------------------------
IFS=""
Sample_eve=`psg proc_s | grep tY`
n=0
for line in $Sample_eve
do
n=`expr $n + 1`
Sam$n=$(`echo $line |awk -F" " {print $5}' |awk -F":" '{print $2}'`)
echo $Sam$n
done
----------------------------
what i am trying to this is..
list all the process named proc_s that are currently running and are on the machine tY..
populate them in the variable Sample_eve.
and then access each line from the Sample_eve and process them on an individual basis.
but it is not happening ..for loop only goes through once..if i do not set IFS="" then line takes word by word data from the $Sample_eve...by which i cannot get seperate start time for each process. (it runs 35 times for 4 lines..i want to make it run only 4 time for 4 line).
i am doing `echo $line |awk -F" " {print $5}' |awk -F":" '{print $2}'` ..so as to get the start time for each process in minutes..then i am assigning it into array Sam so as to get the start Minute for each process.
but getting an output error like this..
for this array assignment as Test[9]: 04^J28^J04^J09: not found.
04, 28,04,09 are correctly shown they are the minutes ..but is not in a proper manner.
i am stuck with this thing .. please help me. I am unable to make the code work.
tried but its not working...echo $Sam[1] is just giving [1].
i also tried to echo the value on n inside the while loop but it is also not printing..
how can i make this run????
-----Post Update-----
Hi
the following code
for(i in sam){
print i
}
for(i in sam){
echo $i
}
both are not showing any output
-----Post Update-----
--------------------------------
Please help...what i want..
1)is to get the time in minutes for a particular process
2)from the list of process generated i have to get its command name and arguments
3)and if it is running for more than 50 mins and has more than 2 argument i have to kill it..
but im unable to complete the no.1 also...please help
thanks.
------------
hi ghostdog74
why have u used
sam[FNR]=a[2]
is it pre declaration of the array Size..as we do in c..
i donno things im asking are silly or not..but im entirely new to shell script and any help from u guys is apreciated..
thanks
Hi guys.. thanks the code is running.
thanks all
Regards.
-----Post Update-----
Hello
is it possible in the above code to get the number of splits that have happened over her..
suppose if the above code goes like this
psg proc_s |awk -F" " '{print all fields }''| while read s
do
n=$(( $n + 1))
Sam[$n]="$s"
done
now in case if i do echo ${#Sam[0]} it gives number of charachters in the Sam[0] array..what if i have to find number of words...i.e to get the
number of spilts per line..how can it be done