LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   awk script (https://www.linuxquestions.org/questions/linux-newbie-8/awk-script-4175457677/)

ines8989 04-10-2013 11:46 AM

awk script
 
Hi
i want to simulate an awk script to have throuĝhput graph for tcp connection ( my awk file is named linktcp) and has this format
BEGIN {
packet_size= 1500
total_throughput = 0
final = 0
time_ini = 1.0
count = 0
}
{
ackn = $5
event = $1
time = $2
node = 0
flowid= $8
from_node = $3
to_node= $4
#print(event)
#print(time)
#print(flowid)
#print(from_node)
#from node should be 2
if(event == "r" && flowid == "1" && from_node == "0" && time_ini >= time && ackn == "tcp" ) {
#remember always immediately after if there will be start of the “{“ .not in next line
total_throughput = total_throughput + packet_size
++count
}
if(event == "r" && flowid == "1" && from_node == "0" && time_ini <= time &&ackn == "tcp") {
#print(count)
count = 0
final = total_throughput + final
#print(total_throughput)
total_throughput = (total_throughput *8)/1000
printf("%f\t%f\n" , time_ini , total_throughput )
total_throughput = 0
time_ini = time_ini + 1
}
}
END {

final = (((final *8)/1000 ) / time)
print("Total Throughput for TCP : " , final)
for (i = 1.00 ; i <= time_ini ; i++) printf("%f\t%f\n" , i , final )
}
to plot the graph of throughput :i wrote this little script below and i named it 'parametre1':
set title 'Tcp-Throughput'
set xlabel 'Time (s)'
set ylabel 'throughput (Mbs)'
set autoscale
plot 'linktcp' w linespoints title 'throughput-of-TCP'
But i tape in the terminal this command to plot the graph with gnuplot : i have this result
gnuplot> load 'parametre1'
"parametre1", line 5: warning: Skipping unreadable file "linktcp"
"parametre1", line 5: No data in plot

Help me please i don't understand what to do
Thanks for you

jpollard 04-10-2013 11:50 AM

You've made it very hard to read -- put code in brackets \[code\] ...\[/code\] (without the \ of course)

The result looks like:
Code:

  put code here

ines8989 04-10-2013 12:08 PM

awk script
 
My script for linktcp.awk file
------------------------------------------------------------------------
BEGIN {

packet_size= 1500
total_throughput = 0
final = 0
time_ini = 1.0
count = 0
}
{

ackn = $5
event = $1
time = $2
node = 0
flowid= $8
from_node = $3
to_node= $4

if(event == "r" && flowid == "1" && from_node == "0" && time_ini >= time && ackn == "tcp" ) {

total_throughput = total_throughput + packet_size
++count
}

if(event == "r" && flowid == "1" && from_node == "0" && time_ini <= time &&ackn == "tcp") {
#print(count)

count = 0
final = total_throughput + final

total_throughput = (total_throughput *8)/1000
printf("%f\t%f\n" , time_ini , total_throughput )
total_throughput = 0
time_ini = time_ini + 1
}
}
END {

final = (((final *8)/1000 ) / time)

print("Total Throughput for TCP : " , final)
for (i = 1.00 ; i <= time_ini ; i++) printf("%f\t%f\n" , i , final )
}

to plot the graph of throughput :i wrote this little script below and i named it 'parametre1':

-------------------------------------------------------------------------------------------------------
set title 'Tcp-Throughput'
set xlabel 'Time (s)'
set ylabel 'throughput (Mbs)'
set autoscale
plot 'linktcp' w linespoints title 'throughput-of-TCP'


when i tape in the terminal this command to plot the graph with gnuplot : i have this result

gnuplot> load 'parametre1'

"parametre1", line 5: warning: Skipping unreadable file "linktcp"
"parametre1", line 5: No data in plot

Help me please i don't understand what to do
Thanks for you

millgates 04-10-2013 01:29 PM

It seems that the file 'linktcp' either does not exist or is unreadable or you are in the wrong directory

ines8989 04-10-2013 02:20 PM

awk script
 
But when i test the awk file it runs that's what i have :

iness@iness-VirtualBox ~/ns-allinone-2.35/bin/FirstCode $ gawk -f linktcp.awk out.tr

I have this result :


91.000000 1008.000000
92.000000 1020.000000
93.000000 1044.000000
94.000000 1044.000000
95.000000 1140.000000
96.000000 1068.000000
97.000000 996.000000
98.000000 1008.000000
99.000000 1020.000000
Total Throughput for TCP : 1014.25
1.000000 1014.247995
2.000000 1014.247995
3.000000 1014.247995
4.000000 1014.247995
5.000000 1014.247995
6.000000 1014.247995
7.000000 1014.247995
8.000000 1014.247995
9.000000 1014.247995


All times are GMT -5. The time now is 06:42 AM.