SUMMARY: whats the best place to share a script : network config

From: Pavic, Aleksander <Aleksander.Pavic_at_t-com.net>
Date: Thu Nov 06 2003 - 10:11:07 EST
Hi again,
as the list does not allow attachments, here is the copy-paste version. (THX to Tony Walsh!)


The Script (called get_network_config) will be available on http://www.sun.com/bigadmin/ @ /Scripts/Utilities in the next days...

CAUTION: This mail is written in Windows. *please laugh now! ;>*
Sometimes M$ adds an '^M' or some other special characters to the end of each line. (While copy-paste)
Remove it or the script will not work!



-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_

#!/sbin/sh


#########################################################################
# ToDO           : Network Configuration Output in "./ntwk_conf"
# Version        : 1.1
# Author         : Aleksander Pavic <nsecret@gmx.de>
# OS             : Sparc@Solaris 8
# Scriptname     : get_network_config
# Licence        : GPL
#########################################################################



filestart()
{
 echo "############# Begin of Network Configuration #################" > ntwk_conf
}




separator()
{
 echo "" >> ntwk_conf
 echo "##############################################################" >> ntwk_conf
 echo "" >> ntwk_conf
}






get_ip()
{
 count_ip="`ndd -get /dev/ip \? | wc -l`"
 count_new_ip="`expr $count_ip - 1`"


  if [ "$noverbose" -eq "1" ]
   then
    ndd -get /dev/ip \? | tail -"$count_new_ip" | awk -F'(' {'print $1'} | grep -v ip_ill_status | grep -v ip_ipif_status | grep -v ipv4_ire_status | grep -v ipv4_mrtun_ire_status | grep -v ipv4_srcif_ire_status | grep -v ipv6_ire_status | grep -v ip_ipc_status | grep -v ip_ndp_cache_report | grep -v ip_proxy_status | grep -v ip_srcid_status | cat > data_ip
     else
      ndd -get /dev/ip \? | tail -"$count_new_ip" | awk -F'(' {'print $1'} > data_ip
  fi



 printf "\n\nBegin IP Config:\n\n" >> ntwk_conf



  for i in `cat data_ip`
   do
    printf "$i=`ndd -get /dev/ip $i`\n" >> ntwk_conf
  done



 printf "\n\nEnd IP Config\n" >> ntwk_conf
 rm data_ip
}





get_tcp()
{
 count_tcp="`ndd -get /dev/tcp \? | wc -l`"
 count_new_tcp="`expr $count_tcp - 1`"



  if [ "$noverbose" -eq "1" ]
   then
    ndd -get /dev/tcp \? | tail -"$count_new_tcp" | awk -F'(' {'print $1'} | grep -v tcp_extra_priv_ports | grep -v tcp_extra_priv_ports_add | grep -v tcp_extra_priv_ports_del | grep -v tcp_status | grep -v tcp_bind_hash | grep -v tcp_listen_hash | grep -v tcp_conn_hash | grep -v tcp_acceptor_hash | grep -v tcp_host_param | grep -v tcp_time_wait_stats | grep -v tcp_host_param_ipv6 | grep -v tcp_1948_phrase | grep -v tcp_close_wait_interval | cat > data_tcp
     else
      ndd -get /dev/tcp \? | tail -"$count_new_tcp" | awk -F'(' {'print $1'} > data_tcp
  fi



 printf "\n\nBegin TCP Config:\n\n" >> ntwk_conf



  for t in `cat data_tcp`
   do
    printf "$t=`ndd -get /dev/tcp $t`\n" >> ntwk_conf
  done



 printf "\n\nEnd TCP Config\n" >> ntwk_conf
 rm data_tcp
}



get_udp()
{
 count_udp="`ndd -get /dev/udp \? | wc -l`"
 count_new_udp="`expr $count_udp - 1`"



  if [ "$noverbose" -eq "1" ]
   then
    ndd -get /dev/udp \? | tail -"$count_new_udp" | awk -F'(' {'print $1'} | grep -v udp_extra_priv_ports | grep -v udp_status | grep -v udp_bind_hash | cat > data_udp
     else
      ndd -get /dev/udp \? | tail -"$count_new_udp" | awk -F'(' {'print $1'} | grep -v udp_bind_hash > data_udp
  fi



 printf "\n\nBegin UDP Config:\n\n" >> ntwk_conf



  for t in `cat data_udp`
   do
    printf "$t=`ndd -get /dev/udp $t`\n" >> ntwk_conf
  done



  # This is a workaround cause ndd tells me that the data comes to fast within the loop
  if [ "$noverbose" -eq "0" ]
   then
    sleep 1
    printf "udp_bind_hash=`ndd -get /dev/udp udp_bind_hash`" >> ntwk_conf
  fi


 printf "\n\nEnd UDP Config\n" >> ntwk_conf
 rm data_udp
}


get_arp()
{
 count_arp="`ndd -get /dev/arp \? | wc -l`"
 count_new_arp="`expr $count_arp - 1`"



  if [ "$noverbose" -eq "1" ]
   then
    ndd -get /dev/arp \? | tail -"$count_new_arp" | awk -F'(' {'print $1'} | grep -v arp_cache_report | cat > data_arp
     else
      ndd -get /dev/arp \? | tail -"$count_new_arp" | awk -F'(' {'print $1'} > data_arp
  fi



 printf "\n\nBegin ARP Config:\n\n" >> ntwk_conf



  for t in `cat data_arp`
   do
    printf "$t=`ndd -get /dev/arp $t`\n" >> ntwk_conf
  done



 printf "\n\nEnd ARP Config\n" >> ntwk_conf
 rm data_arp
}



get_icmp()
{
 count_icmp="`ndd -get /dev/icmp \? | wc -l`"
 count_new_icmp="`expr $count_icmp - 1`"



  if [ "$noverbose" -eq "1" ]
   then
    ndd -get /dev/icmp \? | tail -"$count_new_icmp" | awk -F'(' {'print $1'} | grep -v icmp_status | cat > data_icmp
     else
      ndd -get /dev/icmp \? | tail -"$count_new_icmp" | awk -F'(' {'print $1'} > data_icmp
  fi



 printf "\n\nBegin ICMP Config:\n\n" >> ntwk_conf



  for t in `cat data_icmp`
   do
    printf "$t=`ndd -get /dev/icmp $t`\n" >> ntwk_conf
  done



 printf "\n\nEnd ICMP Config\n" >> ntwk_conf
 rm data_icmp
}



get_int()
{
 count_int="`ndd -get $int_val \? | wc -l`"
 count_new_int="`expr $count_int - 1`"
 ndd -get "$int_val" \? | tail -"$count_new_int" | awk -F'(' {'print $1'} > data_int


 printf "\n\nBegin Interface Config:\n\n" >> ntwk_conf



  for int in `cat data_int`
   do
    printf "$int=`ndd -get $int_val $int`\n" >> ntwk_conf
  done



 printf "\n\nEnd Interface Config\n" >> ntwk_conf
 rm data_int
}





################# Action #################





if [ "$#" -gt "10" ]
 then
  echo "Usage: $0 {interface_dev | -inst [] | -i | -t | -u | -a | -ic | -n | -j }"
  exit 1
fi





noverbose="0"
with_int="0"
int_val="0"
instance_id="0"
option_counter="0"
want_ip="0"
want_tcp="0"
want_udp="0"
want_arp="0"
want_icmp="0"
want_justint="0"








if [ "$1" = "-h" -o "$1" = "--help" ]
 then
  echo ""
  echo "Usage: $0 {interface_dev | -inst [] | -i | -t | -u | -a | -ic | -oi | -n | -v}"
  echo ""
  echo ""
  echo " general options:"
  echo ""
  echo "  <interface_dev> - path to interface device"
  echo "  -inst []        - specify an instance"
  echo "  -v              - version"
  echo "  -h or --help    - this screen"
  echo ""
  echo ""
  echo " output modifiers:"
  echo ""
  echo "  -i              - ip config output"
  echo "  -t              - tcp config output"
  echo "  -u              - udp config output"
  echo "  -a              - arp config output"
  echo "  -ic             - icmp config output"
  echo "  -oi             - only interface output (other modifiers will be ignored)"
  echo "  -n              - no verbose mode"
  echo ""
  echo ""
  echo " DEFAULTS:"
  echo "  If no modifier specified - !ALL! possible output is given to ./ntwk_conf"
  echo "  output modifiers cannot change the output sequence in ntwk_conf"
  echo ""
  echo ""
  echo " no verbose keeps back the following:"
  echo "  - all obsolet things"
  echo "  - every output greater than one line"
  echo ""
  echo " Format in ntwk_conf as follows:"
  echo "  <Attribute>=<value>"
  echo ""
  echo " CAUTION: some ints don't need an instance - like /dev/bge2"
  echo "  Options not known by the script will be ignored"
  echo ""
  echo " LIMITATIONS:"
  echo "  The Script handles only one Interface/instance"
  echo "  WORKAROUND: Invoke the Script multiple times with '-oi' to report multiple Interfaces/instances"
  echo ""
  exit 0
fi




if [ "$1" = "-v" ]
 then
  echo "Version: 1.1"
  exit 0
fi




# determine which parameter is our interface

if [ -c "$1" ]
 then
  with_int="1"
  int_val="$1"

   elif [ -c "$2" ]
    then
     with_int="2"
     int_val="$2"

      elif [ -c "$3" ]
       then
        with_int="3"
        int_val="$3" 

         elif [ -c "$4" ]
          then
           with_int="4"
           int_val="$4" 

            elif [ -c "$5" ]
             then
              with_int="5"
              int_val="$5"

               elif [ -c "$6" ]
                then
                 with_int="6"
                 int_val="$6"

                  elif [ -c "$7" ]
                   then
                    with_int="7"
                    int_val="$7"

                     elif [ -c "$8" ]
                      then
                       with_int="8"
                       int_val="$8"

                        elif [ -c "$9" ]
                         then
                          with_int="9"
                          int_val="$9"
        
                           elif [ -c "$10" ]
                            then
                             with_int="10"
                             int_val="$10"

                              else
                               with_int="0"
                               int_val="0"
fi







# store the instance value

if [ "$1" = "-inst" ]
 then
  instance_id="$2"

   elif [ "$2" = "-inst" ]
    then
     instance_id="$3"

      elif [ "$3" = "-inst" ]
       then
        instance_id="$4"

         elif [ "$4" = "-inst" ]
          then
           instance_id="$5"

            elif [ "$5" = "-inst" ]
             then
              instance_id="$6"

               elif [ "$6" = "-inst" ]
                then
                 instance_id="$7"

                  elif [ "$7" = "-inst" ]
                   then
                    instance_id="$8"

                     elif [ "$8" = "-inst" ]
                      then
                       instance_id="$9"

                        elif [ "$9" = "-inst" ]
                         then
                          instance_id="$10"

                           else
                            instance_id="noval"
fi




# catch user errors

      if [ "$with_int" -eq "0" -a "$instance_id" != "noval" ]
       then
        echo "You cannot specify an instance without interface"
        exit 2

        elif [ "$instance_id" = "-n" ]
         then
          echo "no existing instance"
          exit 4

# A must be if there exists only one interface 

           elif [ "$instance_id" = "noval" ]
            then
             instance_id="0"


               elif [ "$with_int" -ne "0" ]
                then
                 ndd_error=`ndd -set "$int_val" instance "$instance_id"`

# Cause ndd give a text message instead of an non zero exit code

                    if [ -n "$ndd_error" ] 
                     then
                      echo "no existing instance"
                       exit 3
                    fi


fi






# output modifiers

# ip option  

 if [ "$1" = "-i" -o "$2" = "-i" -o "$3" = "-i" -o "$4" = "-i" -o "$5" = "-i" -o "$6" = "-i" "$7" = "-i" -o "$8" = "-i" -o "$9" = "-i" -o "$10" = "-i" ]
  then
   want_ip="1"
   option_counter="1"
 fi




# tcp option

 if [ "$1" = "-t" -o "$2" = "-t" -o "$3" = "-t" -o "$4" = "-t" -o "$5" = "-t" -o "$6" = "-t" "$7" = "-t" -o "$8" = "-t" -o "$9" = "-t" -o "$10" = "-t" ]
  then
   want_tcp="1"
   option_counter="2"
 fi


# udp option

 if [ "$1" = "-u" -o "$2" = "-u" -o "$3" = "-u" -o "$4" = "-u" -o "$5" = "-u" -o "$6" = "-u" "$7" = "-u" -o "$8" = "-u" -o "$9" = "-u" -o "$10" = "-u" ]
  then
   want_udp="1"
   option_counter="3"
 fi


# arp option

 if [ "$1" = "-a" -o "$2" = "-a" -o "$3" = "-a" -o "$4" = "-a" -o "$5" = "-a" -o "$6" = "-a" "$7" = "-a" -o "$8" = "-a" -o "$9" = "-a" -o "$10" = "-a" ]
  then 
   want_arp="1"
   option_counter="4"
 fi


# icmp option

 if [ "$1" = "-ic" -o "$2" = "-ic" -o "$3" = "-ic" -o "$4" = "-ic" -o "$5" = "-ic" -o "$6" = "-ic" "$7" = "-ic" -o "$8" = "-ic" -o "$9" = "-ic" -o "$10" = "-ic" ]
  then
   want_icmp="1"
   option_counter="5"
 fi


# only interface option

 
 if [ "$1" = "-oi" -o "$2" = "-oi" -o "$3" = "-oi" -o "$4" = "-oi" -o "$5" = "-oi" -o "$6" = "-oi" "$7" = "-oi" -o "$8" = "-oi" -o "$9" = "-oi" -o "$10" = "-oi" ]
  then
   want_justint="1"
   option_counter="6"
 fi


# wish a no verbose?

if [ "$1" = "-n" -o "$2" = "-n" -o "$3" = "-n" -o "$4" = "-n" -o "$5" = "-n" -o "$6" = "-n" -o "$7" = "-n" -o "$8" = "-n" -o "$9" = "-n" -o "$10" = "-n" ]
 then
  noverbose="1"
   else
    noverbose="0"
fi



# the decision process

 filestart;

  if [ "$want_justint" -eq "0" ]
   then

    if [ "$want_ip" = "1" -o "$option_counter" = "0" ]
     then
      get_ip;
      separator;
    fi


    if [ "$want_tcp" = "1" -o "$option_counter" = "0" ]
     then
      get_tcp;
      separator;
    fi


    if [ "$want_udp" = "1" -o "$option_counter" = "0" ]
     then
      get_udp;
      separator;
    fi


    if [ "$want_arp" = "1" -o "$option_counter" = "0" ]
     then
      get_arp;
      separator;
    fi


    if [ "$want_icmp" = "1" -o "$option_counter" = "0" ]
     then
      get_icmp;
      separator;
    fi

    if [ "$with_int" -ne "0" ]
     then
     get_int;
    fi

      else

       if [ "$with_int" -ne "0" ]
        then
         get_int;
          else
           echo "give me an interface device"
           exit 5
       fi
  

fi


 printf "Finished!\n"
 exit 0

-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-


greetz
Aleks

___________________________________________________________________________________________
Original messages:

Hi all,
a lot of people said that i should start in this list and then try the Big Admin Site.

I'm a script beginner, so please don't hurt me for not efficient code.
Tips for optimizing are very welcome!! ;-D
The script is appended is this mail.

It must be started with root privileges cause ndd is used to determine the config.
Start with "./gnc -h" to see whats possible and how it works.

I hope that helps some of you!

Thanks to all!

regards
aleks

--------------------------------------------------------------------------------------------
Hi all,
i wrote a script which reads network configuration on a sun box and writes this to a file.
As i know nobody has done this until now...
I want to share it so people can benfit from this (comparing configs in case of network problems, as we had ;D ).

Where is the best Place to do that?

greetz 
Aleks
_______________________________________________
sunmanagers mailing list
sunmanagers@sunmanagers.org
http://www.sunmanagers.org/mailman/listinfo/sunmanagers
Received on Thu Nov 6 10:16:54 2003

This archive was generated by hypermail 2.1.8 : Thu Mar 03 2016 - 06:43:20 EST