how do i get current bandwidth usage via shell script?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how do i get current bandwidth usage via shell script?
# 1  
Old 05-25-2008
how do i get current bandwidth usage via shell script?

hello unix-people.

can u please tell me how i can get the current bandwidth usage of my machine on shell into variables?

thanks a lot
# 2  
Old 05-25-2008
i now tried this
Code:
iptraf -g -t 1 > /tmp/somefile

after that i have the screen output of iptraf in that file and it looks like this
Code:
0.00 kbits/sec 153.80 kbits/sec Elapsed time: 0:00 2323443535515177707081814455919133204204556677121299222233414122585865657777888080119393235.4445530130122131344353566575799636399707082823344556691914034031616252566424299545416.2996060727233448080119292335115115528284040229950506262334455667772723384846036031866222230302299414152523344556060117272339944710710882020119931314242334455667790.45353446565668585808099181821212234345566774242515144696976768383999990190133208.0441155282899303066774646575765656685859995956610021002441515667723233535168.8484855557775759982823399909010210233445577881010116677282899445050113375756688848455979799214.4200200117788191920204141226161557474558787889990901166773083089930304646545455636344767636778899848455949455413413443232774343505011636355667788997575668787885065061010262634346641414455575768899606055777788818188601601771313282831314466484899505011223344997070111418282939370970917179920206677404011223366778851514477646499707093934481081077992424663737213.81 [5

i can extract the value from there,

but is there a more elegant way to achieve my goal?

thanks m8s
# 3  
Old 05-25-2008
okay guys,
i finally made it:
Code:
bw=`iptraf -g -t 1 | sed 's/[^a-z0-9 ]/\n/g'`
bw=`expr "x$bw" : 'x\(.*\)kbit' | sed -e '$!{h;d;}' -e x`
bw=`echo $bw | sed 's/[ ]//g'`
echo $bw

it now gives me back the bandwidth utilization

but i am sure someone has a better solution.

please help me out or comment on my script.

thanks people!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Detect current shell inside a script

I wish to print my current shell which happens to be bash in my script check.sh more check.sh echo $0 echo `ps -p $$` But instead of printing it prints check.sh i.e the name of the script for both the commands. Can you please suggest how to print the current shell i m on inside the... (2 Replies)
Discussion started by: mohtashims
2 Replies

2. Shell Programming and Scripting

Shell script to calculate the max cpu usage from the main script

Hi All, I have a script which does report the cpu usuage, there are few output parameter/fields displayed from the script. My problem is I have monitor the output and decide which cpu number (column 2) has maximum value (column 6). Since the output is displayed/updated every seconds, it's very... (1 Reply)
Discussion started by: Optimus81
1 Replies

3. Shell Programming and Scripting

Need help to make a shell script with usage

Hello, I begin to write my first shell script, but I am totally lost, hope you can help me. I'd like to write a script with some conditions and multiples usages: ./myscript.sh -i <host> or ./myscript.sh -e <host> Have you some suggestion, because I am really lost, I try to do something... (12 Replies)
Discussion started by: Francesco
12 Replies

4. Shell Programming and Scripting

Passing argument to a script while executing it within current shell

Hi Gurus, I have written a script set_env.ksh to which I pass an argument and set the oracle login credentials based on the argument I pass. The script has code as below. ORACLE_SID=$1 DB_SCHEMA_LOGON=$DB_SCHEMA_USER/$DB_SCHEMA_PASSWORD@$ORACLE_SID; export DB_SCHEMA_LOGON; echo... (3 Replies)
Discussion started by: Sabari Nath S
3 Replies

5. Shell Programming and Scripting

Substracting days from current date(K shell script)

Hi, I want to subtract 'n' days from the current timestamp in a k shell script. Is there any inbuilt function to do it or any workaround solution to get the date. And I want the output to be in YYYY:MM:DD HH:MM:SS format. Please help. Thanks in advance. (4 Replies)
Discussion started by: Suryaaravindh
4 Replies

6. Shell Programming and Scripting

current line number in shell script

Hi I am using korn shell is there a built in or ny other way to get the current line number so i can write the current line number to the logfile to aid in debugging like logmsg $lineno $date logmsg is a helper function that helps in logging messages to a log file regards (3 Replies)
Discussion started by: xiamin
3 Replies

7. Solaris

current CPU usage, memory usage, disk I/O oid(snmp)

Hi, I want to monitor the current cpu usage, monitor usage , disk I/o and network utlization for solaris using SNMP. I want the oids for above tasks. can you please tell me that Thank you (2 Replies)
Discussion started by: S_venkatesh
2 Replies

8. Shell Programming and Scripting

Trigger Shell Script from Current Script

Hello all, I'm new to shell programming and need some help. I would like to set up a step within a shell script to trigger another shell script to run, based on the highest return code generated in the current script. For example, if the highes return code value in the current script is less... (1 Reply)
Discussion started by: mmignot
1 Replies

9. Shell Programming and Scripting

How do i execute script in the current shell

How do i run a shell script or perl script with in the context of a current shell. I know that i can use command source. but we can't pass any arguments to our script if we use source command as it takes only one argement i.e filename Is there any way to run a script in the current shell... (5 Replies)
Discussion started by: Naresh Kumar
5 Replies

10. UNIX for Dummies Questions & Answers

Commnad for getting bandwidth usage

Hi all Wanted to know if there is a command that gives me the bandwidth used at any point of time (in mbps). I pay for the bandwidth I have used and need to be alerted everytime I corss over a certain limit. Regards KS (5 Replies)
Discussion started by: skotapal
5 Replies
Login or Register to Ask a Question