LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-11-2005, 10:54 PM   #1
hmib
LQ Newbie
 
Registered: Aug 2004
Posts: 11

Rep: Reputation: 0
bash script


hi all,

how to write a bash script that retrieves statistics from netstat, displays the number of packets incoming per second and then convert the number of packets to bytes/bits and display that as well?
 
Old 01-12-2005, 12:22 AM   #2
student04
Member
 
Registered: Jan 2004
Location: USA
Distribution: macOS, OpenBSD
Posts: 669

Rep: Reputation: 34
Bash scripting is like using the console... what might be useful to you are gawk, head and tail to display the right information from netstat. You can also do math in bash scripting, to convert the bytes to bits and vice versa (8 bits per byte..)

This might be of some use: http://www.tldp.org/LDP/abs/html/index.html or simply the main site http://www.tldp.org/guides.html

You might also want to search http://freshmeat.net and http://sourceforge.net for scripts that might have already been written.
 
Old 01-12-2005, 12:36 AM   #3
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
I think you wanted the total pkts received ( ? ) If so, here's the first part...
Code:
#!/bin/bash

for i in `netstat |grep '[0-9]'|awk '{print$2}'`;do
a=$(($a + $i ))
done
echo Total received pkts is $a
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash script Linh Programming 4 04-21-2004 05:19 PM
send automatic input to a script called by another script in bash programming jorgecab Programming 2 04-01-2004 12:20 AM
bash script - incrementing a filename in a script tslinux Programming 10 08-05-2003 11:58 PM
bash script brian0918 Programming 7 06-12-2003 06:06 PM
bash script prob: how can i tell the script that a 'dd' has finished? Frustin Linux - General 2 04-02-2003 05:34 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:18 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration