I'm working currently in a shell script to monitor a Solaris system. The main purpose of the script is show info like: Memory, Network, etc.

In the Network part, it will show info like arp table, available network interfaces, etc.

The thing is, the script is not only for a one system, so, the others have different nics. For example: for one of them I have the net1, and in an other I have bge0. I need to create a function to evaluate if the interface is net1 shows the result of this comand:

ifconfig -a | grep [network interface name]

The script will evaluate things like: if the OS is Solaris 10 then, show the nic available and ip that it use, in case that the OS will be a Solaris 11 then, show [other part....]

I hope to be very clear explaining this.

I used ifconfig command instead ipadm because I have Solaris 10 and Solaris 11 systems actually.

closed as unclear what you're asking by jlliagre, Anthon, garethTheRed, MelBurslan, Jakuje Apr 14 '16 at 18:59

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    Can you clarify exactly what information you want to display. There has been a lot of changes between Solaris 10 and 11, especially network virtualization (crossbow) / vanity naming. You can list all interfaces with kstat -c net ":::link_state" on both versions, but on the latter a single physical interface will show up more than once. There are also interfaces that might be partially or fully dedicated to non global zones, even kernel zones. – jlliagre Apr 14 '16 at 14:01
  • Make a system specific file for each system and include that at the top of your script. – Anthon Apr 14 '16 at 15:15

You first need to call ifconfig -a plumb to get all potential interfaces plumbed before you can check the list.

Note that ifconfig -a only lists plumbed interfaces, while ifconfig -a plumb really applies to all interfaces - even those that are not yet plumbed.

Note that you cannot configure unplumbed interfaces. Regardless on whether you like to call ifconfig xxx0 up or ifconfig xxx0 dhcp. You first need to plumb an interface to make it usable. Even listing an interface via ifconfig xxx0 will only work after it has been plumbed.

  • I use this command to list all network interfaces that I used in my so. dladm show-link | awk '{print $1}' Alternatively I use this one: dladm show-phys – vicdeveloper Apr 14 '16 at 13:22
  • But this only works on newer Solaris versions. The ifconfig -a plumb method works always. – schily Apr 14 '16 at 14:05
  • I got this message executing this command: ifconfig: cannot plumb net1: Interface already exists ifconfig: cannot plumb net0: Interface already exists – vicdeveloper Apr 14 '16 at 14:11
  • 1
    You should not use ifconfig -a plumb on Solaris 11. You will use ipadm and dladm to configure network interfaces on Solaris 11. – Lambert Apr 14 '16 at 14:25
  • 1
    Why not, it works is generally a bad idea. The answer I've given uses a) commands that both Solaris 10 and Solaris 11 have in common, b) to ease the programming by the OP to have the ability to create a generic function, c) does not change anything on the system (which monitoring is supposed to). – Lambert Apr 14 '16 at 14:42

Perhaps I do not fully understand your question but I read it as if you want to check if all the installed interfaces are configured or not.

To see installed interfaces, you can use dladm show-link|grep -v "LINK"|awk '{print $1}' on both to get a list of interface links.

You can use this list as input to retrieve the desired ifconfig output:

for NIC in $(dladm show-link|grep -v "LINK"|awk '{print $1}'); do ifconfig $NIC; done;
  • I got this error executing: ifconfig: status: SIOCGLIFFLAGS: nxge0: no such interface ifconfig: status: SIOCGLIFFLAGS: nxge1: no such interface ifconfig: status: SIOCGLIFFLAGS: nxge2: no such interface ifconfig: status: SIOCGLIFFLAGS: nxge3: no such interface – vicdeveloper Apr 14 '16 at 14:07
  • The proposed command has not been tested and it will not work. See my answer for a working method. – schily Apr 14 '16 at 14:10
  • @schily, what makes you think this is a) not tested and b) not working? That the OP receives nxge0: no such interface messages just indicates that the interface is not configured. Another way is to iterate through the list and perform ifconfig |grep "$NIC" if you want to see output only for configured entries. But in that case, why filtering for an interface at all instead of parsing ifconfig -a output? – Lambert Apr 14 '16 at 14:23
  • No, it indicated that the interface has not been plumbed. This is why your script fails: It does not do the needed plumbing. – schily Apr 14 '16 at 14:25
  • To avoid a long discussion, but is 'not configured' in this case not equal to 'not plumbed'? – Lambert Apr 14 '16 at 14:27

Not the answer you're looking for? Browse other questions tagged or ask your own question.