solaris (netstat)

Documentation: Network Monitoring
source:http://www.brendangregg.com/Perf/network.html

The following is a guide to monitoring network interfaces and the network from the Solaris operating system.
Note: This document is not written by Sun.
Brendan Gregg, 09-Oct-2005, version 0.70.


Is your network busy?

The network often gets blamed when things are performing poorly, and perhaps this is correct - your network interfaces may be running at 100% utilisation.

What command will tell you how busy the network interface is? Many sysadmins suggest using netstat -i to find out,

$ netstat -i 1
    input   hme0      output           input  (Total)    output
packets errs  packets errs  colls  packets errs  packets errs  colls
70820498 6     73415337 0     0      113173825 6     115768664 0     0  
242     0     149     0     0      246     0     153     0     0
1068    0     552     0     0      1075    0     559     0     0
[...]

 

Read more...

Bash IFS variable

Wednesday, 30 December 2009 13:17 uster
Print PDF

 

Using the Bash IFS variable to make for loops split with non whitespace characters

 

A basic for loop

The Bash for loop splits using a whitespace (space, tab or newline). This allows you to easily iterate over a glob of values, as follows (this particular example uses a glob of filenames, taken from a backup script that requires a list of files to exclude from the backup):

Script:

#!/bin/bash
vals='/mnt /dev /proc /sys /tmp /usr/portage /var/tmp'
for i in $vals; do echo $i; done

Output:

/mnt
/dev
/proc
/sys
/tmp
/usr/portage
/var/tmp

The problem

A problem arises when one of the values in the glob needs to contain a space. Take the following example:

#!/bin/bash
vals='/mnt /var/lib/vmware/Virtual Machines /dev /proc /sys /tmp /usr/portage /var/tmp'
for i in $vals; do echo $i; done

Output:

/mnt
/var/lib/vmware/Virtual
Machines
/dev
/proc
/sys
/tmp
/usr/portage
/var/tmp

"/var/lib/vmware/Virtual Machines" is split because it contains a space, which would obviously be a major problem if you were attempting to do something with each file location rather than just echoing it.

The IFS internal variable

One way around this problem is to change Bash's internal IFS (Internal Field Separator) variable so that it splits fields by something other than the default whitespace (space, tab, newline), in this case, a comma.

#!/bin/bash
IFS=$','
vals='/mnt,/var/lib/vmware/Virtual Machines,/dev,/proc,/sys,/tmp,/usr/portage,/var/tmp'
for i in $vals; do echo $i; done
unset IFS

Output:

/mnt
/var/lib/vmware/Virtual Machines
/dev
/proc
/sys
/tmp
/usr/portage
/var/tmp

It's best to unset IFS after you've done your work, with unset IFS, so that it returns to its default value. This will avoid any potential problems that could arise in the rest of your script.

 

source:

http://mindspill.net/computing/linux-notes/using-the-bash-ifs-variable-to-make-for-loops-split-with-non-whitespace-characters.html

Last Updated on Wednesday, 30 December 2009 13:24
 

What is your Linux Desktop OS?











Who's Online+

  • [Bot]
Now online:
  • 1 guest
  • 1 robot
Total members: 0

Who's Online

We have 2 guests online

Statistics

Content View Hits : 15714