Friday, March 17, 2017

How to check which process is holding the port

How to check which process is holding the port

Most of the time we are in situation to find the process which is holding the same port which may cause the application issues. This post will help us whenever we are in same position. Yes, we can find the  process with using port in different methods. Let we start to search it.....

root@unixrock # ndd /dev/tcp tcp_listen_hash
    TCP            zone IP addr         port  seqnum   backlog (q0/q/max)
----skipped------
281 ffffffff81d46440 0 ::ffff:127.0.0.1 00025 00000000 0/0/16
----skipped------
from the above output we can find the process of the port 25, please follow the below steps
root@unixrock # mdb -k
Loading modules:[unix krtld genunix specfs dtrace cpu.generic uppc pcplusmp ufs md mpt ip hook neti sctp arp usba fctl nca lofs audiosup cpc fcip random crypto zfs logindmux ptm sppp sata nfs]
>
> ffffffff81d46440::print tcp_t tcp_rq
tcp_rq = 0xffffffff8961f028
>
> 0xffffffff8961f028::q2stream
ffffffff87052e10
>
> ffffffff87052e10$ 0xffffffff874bc780::whereopen
file ffffffff893689d8
ffffffff88dc8900
>
> ffffffff88dc8900::ps
S    PID   PPID   PGID    SID    UID      FLAGS             ADDR NAME
R    935      1    935    935      0 0x52010000 ffffffff88dc8900 sendmail
>
root@unixrock #
Yes !!! we have found the process (sendmail) which using the port 25

we can use lsof utility to find the process with using port. although lsof will not be available on all solaris server, we have to install the lsof package. NOTE : This utlity can't be used in Non-global zones.
root@unixrock # /usr/local/bin/lsof -i :25
lsof: WARNING: access /.lsof_unixrock: No such file or directory
lsof: WARNING: created device cache file: /.lsof_unixrock
COMMAND  PID USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
sendmail 935 root    5u  IPv4 0xffffffff81d46240      0t0  TCP localhost:smtp (LISTEN)
root@unixrock #
Yes, we have found the process with using port by using lsof utility.

Now our concern would be how to check the process with using port in non-global zone level. Yes, we have the option to do that by using our customized script. Please follow the steps...
root@unixrock # cat /var/tmp/check_port.sh
#!/bin/ksh

CODE='---------------------------------------------'
PID=$(/usr/bin/ps -ef | sed 1d | awk '{print $2}')

if [ $# -eq 0 ]; then
   read PORT?"Enter port you would like to know pid for: "
else
   PORT=$1
fi

for f in $PID
do
   /usr/proc/bin/pfiles $f 2>/dev/null | /usr/xpg4/bin/grep -q "port: $PORT"
   if [ $? -eq 0 ]; then
      echo $CODE
      echo "Port: $PORT is being used by PID:\c"
      /usr/bin/ps -ef -o pid -o args | egrep -v "grep|pfiles" | grep $f
   fi
done
exit 0
root@unixrock #

Copy the script and executed as mentioned below
root@unixrock # /var/tmp/check_port.sh
Enter port you would like to know pid for: 25
---------------------------------------------
Port: 25 is being used by PID:  935 /usr/lib/sendmail -bl -q15m
root@unixrock #
Yes...We have found the process with using the port by executing customized scripts.

How to change hostname in Solaris 11

 How to change hostname in Solaris 11

Here is the step by step procedure to change/rename hostname on Solaris 11. In Solaris 10 all we know that we need to edit few files in order to change the hostname, but in Solaris 11 we need to change the hostname in SMF service level. Let we can start doing that.

Checking the SMF Services
root@unixrock_SOL11:~# svcs -a|grep -i node
online         21:53:28 svc:/system/identity:node
root@unixrock_SOL11:~#
Checking the current property settings
root@unixrock_SOL11:~# svccfg -s system/identity:node
svc:/system/identity:node> listprop config
config                       application
config/enable_mapping       boolean     true
config/ignore_dhcp_hostname boolean     true
config/nodename             astring     unixrock_SOL11
config/loopback             astring     unixrock_SOL11
svc:/system/identity:node>
Change/Rename the hostname entries
root@unixrock_SOL11:~# svccfg -s system/identity:node
svc:/system/identity:node>
svc:/system/identity:node> setprop config/nodename=unixrocks11
svc:/system/identity:node> setprop config/loopback=unixrocks11
svc:/system/identity:node>
Verifying the changes
root@unixrock_SOL11:~# svccfg -s system/identity:node
svc:/system/identity:node> listprop config
config                       application
config/enable_mapping       boolean     true
config/ignore_dhcp_hostname boolean     true
config/nodename             astring     unixrocks11
config/loopback             astring     unixrocks11
svc:/system/identity:node>
Restart the service to take effect the changes
root@unixrock_SOL11:~# svccfg -s system/identity:node refresh
root@unixrock_SOL11:~# svcadm restart system/identity:node
root@unixrock_SOL11:~# svccfg -s system/identity:node listprop config
config                       application
config/enable_mapping       boolean     true
config/ignore_dhcp_hostname boolean     true
config/nodename             astring     unixrocks11
config/loopback             astring     unixrocks11
root@unixrock_SOL11:~# hostname
unixrocks11
root@unixrock_SOL11:~#
Cool and simple way to do the hostname changes in Solaris 11. You can see the changes while opening new session.

Thanks for reading this post. Please leave your valuable comments and queries, I will get back to you at earliest

Solaris 11 - Image Packaging System Basics (IPS)

Solaris 11 - Image Packaging System Basics (IPS)

Last Post we saw how to configure local repository on Solaris 11 server. In this post we will see the brief of New IPS features and troubleshoot methods, Installing and uninstalling the packages, checking the packages contents and package dependencies and package manifest basics and understanding the packages components.

Basics of Repository :
  • Administrators can suggest whether we required Oracle repository or Local repository depends on environment requirements.
  • Oracle Solaris 11 installations will come up with default publisher http://pkg.oracle.com/solaris/release which supplies all packages from the oracle release repository.
  • Administrators can install new software packages, search the content of package or mirror the contents of that repository locally.
  • Oracle Solaris 11 having many IPS pkg command which query the system with using option "list, info, content, search, history can be performed by users.
Basics of Packages FMRI:
below output you can understand the brief about the structure of package FMRI (Fault Managed Resources Identifier).






Listing installed Packages in that server
root@unixrock:~# pkg list |more
NAME (PUBLISHER)                                  VERSION                    IFO
archiver/gnu-tar                                  1.26-0.175.1.0.0.24.0      i--
audio/audio-utilities                             0.5.11-0.175.1.0.0.24.2    i--
codec/flac                                        1.2.1-0.175.0.0.0.0.0      i--
codec/libtheora                                   1.1.1-0.175.1.0.0.15.0     i--
codec/ogg-vorbis                                  2.30.0-0.175.1.0.0.12.0    i--
codec/speex                                       1.2-0.175.1.0.0.15.0       i--
communication/im/pidgin                           2.10.5-0.175.1.0.0.24.0    i--
compress/bzip2                                    1.0.6-0.175.1.0.0.24.0     i--
compress/gzip                                     1.4-0.175.1.0.0.24.0       i--
compress/p7zip                                    9.20.1-0.175.1.0.0.24.0    i--
compress/unzip                                    6.0-0.175.1.0.0.24.0       i--
compress/xz                                       5.0.1-0.175.1.0.0.24.0     i--
compress/zip                                      3.0-0.175.1.0.0.24.0       i--
---------Few lines are confiscated---------------------------------------------- 
x11/xfontsel                                      1.0.4-0.175.1.0.0.24.1317  i--
x11/xfs                                           1.1.2-0.175.1.0.0.24.1317  i--
x11/xfs/xfs-utilities                             7.7-0.175.1.0.0.24.1317    i--
x11/xkill                                         1.0.3-0.175.1.0.0.24.1317  i--
x11/xlock                                         0.5.11-0.175.1.0.0.24.1317 i--
x11/xmag                                          1.0.4-0.175.1.0.0.24.1317  i--
x11/xvidtune                                      1.0.2-0.175.1.0.0.24.1317  i--
root@unixrock:~# 
 
Listing the Version information of particular pkg
root@unixrock:~# pkg list diagnostic/tcpdump
NAME (PUBLISHER)                                  VERSION                    IFO
diagnostic/tcpdump                                4.1.1-0.175.1.0.0.24.0     i--
root@unixrock:~# 
Checking detailed information about the particular pkg
root@unixrock:~# pkg info diagnostic/tcpdump
          Name: diagnostic/tcpdump
       Summary: network traffic sniffer
   Description: A tool for network monitoring and data acquisition
      Category: Applications/Internet
         State: Installed
     Publisher: solaris
       Version: 4.1.1
 Build Release: 5.11
        Branch: 0.175.1.0.0.24.0
Packaging Date: September  4, 2012 05:17:58 PM
          Size: 1.24 MB
          FMRI: pkg://solaris/diagnostic/tcpdump@4.1.1,5.11-0.175.1.0.0.24.0:20120904T171758Z
root@unixrock:~#
 
Checking contents of particular pkg which shows the complete installation path.
root@unixrock:~# pkg contents diagnostic/tcpdump
PATH
usr
usr/sbin
usr/sbin/tcpdump
usr/share
usr/share/man
usr/share/man/man1
usr/share/man/man1/tcpdump.1
root@unixrock:~#
 
Checking the package history for the recent updates and changes.
root@unixrock:~# pkg history
START                    OPERATION                CLIENT             OUTCOME
2012-09-20T01:18:22      set-property             transfer module    Succeeded
2012-09-20T01:18:22      add-publisher            transfer module    Succeeded
2012-09-20T01:18:22      refresh-publishers       transfer module    Succeeded
2012-09-20T01:18:22      image-create             transfer module    Succeeded
2012-09-20T01:18:30      rebuild-image-catalogs   transfer module    Succeeded
2012-09-20T01:18:36      set-property             transfer module    Succeeded
2012-09-20T01:18:37      install                  transfer module    Succeeded
2012-09-20T02:00:12      update-publisher         transfer module    Succeeded
2012-09-20T02:00:12      refresh-publishers       transfer module    Succeeded
2014-09-31T23:37:48      refresh-publishers       pkg                Failed
2014-09-31T23:37:48      update                   pkg                Failed
2014-08-11T21:34:42      refresh-publishers       pkg                Succeeded
 
Checking the all package Integrity
root@unixrock:~# pkg verify
pkg://solaris/desktop/administration/nwam-manager                 55/847 / 
Checking the particular package Integrity
root@unixrock:~# pkg verify diagnostic/tcpdump
root@unixrock:~#
 
Searching particular packages with details
root@unixrock:~# pkg search -l diagnostic/tcpdump
INDEX       ACTION VALUE                                          PACKAGE
group       depend diagnostic/tcpdump                             pkg:/group/system/solaris-desktop@0.5.11-0.175.1.0.0.24.3
incorporate depend pkg:/diagnostic/tcpdump@4.1.1-0.175.1.0.0.24.0 pkg:/consolidation/userland/userland-incorporation@0.5.11-0.175.1.0.0.24.0
pkg.fmri    set    solaris/diagnostic/tcpdump                     pkg:/diagnostic/tcpdump@4.1.1-0.175.1.0.0.24.0
root@unixrock:~#
 
rebuild the repo index whenever search performance is degraded
root@unixrock:~# pkg rebuild-index
PHASE                                          ITEMS
Building new search index                    847/847
root@unixrock:~#
 
Installing the particular package
root@unixrock:~# pkg install diagnostic/tcpdump
           Packages to install:  1
       Create boot environment: No
Create backup boot environment: No

DOWNLOAD                                PKGS         FILES    XFER (MB)   SPEED
Completed                                1/1           6/6      0.4/0.4    0B/s

PHASE                                          ITEMS
Installing new actions                         20/20
Updating package state database                 Done
Updating image state                            Done
Creating fast lookup database                   Done
Reading search index                            Done
Updating search index                            1/1
root@unixrock:~#
 
Checking the dependency packages
root@unixrock:~# pkg contents -r -o fmri,type -t depend diagnostic/tcpdump
FMRI                                               TYPE
pkg:/system/library/libpcap@1.1.1-0.175.1.0.0.23.0 require
pkg:/system/library@0.5.11-0.175.1.0.0.23.0        require
root@unixrock:~#
 
Uninstalling the package
root@unixrock:~# pkg uninstall diagnostic/tcpdump
            Packages to remove:  1
       Create boot environment: No
Create backup boot environment: No

PHASE                                          ITEMS
Removing old actions                           14/14
Updating package state database                 Done
Updating package cache                           1/1
Updating image state                            Done
Creating fast lookup database                   Done
Reading search index                            Done
Updating search index                            1/1
root@unixrock:~#
 
Solaris 11 IPS will update your system to latest packages with single command "pkg update". Even though we can execute the command with "-nv" option for a dry run to get an idea about the work which needs to be completed.
root@unixrock:~# pkg update -nv
No updates available for this image.
root@unixrock:~#
Trying to update the particular packages from repo
root@unixrock:~# pkg update diagnostic/tcpdump
No updates available for this image.
root@unixrock:~#
 
List the publisher with local repository
root@unixrock:~# pkg publisher
PUBLISHER                   TYPE     STATUS P LOCATION
solaris                     origin   online F file:///unixrepo/repo/repo/
root@unixrock:~#
root@unixrock:~#
 
Listing the local repository packages
root@unixrock:~# pkgrepo -s /unixrepo/repo/repo/ list|more
PUBLISHER NAME                                          O VERSION
solaris   BRCMbnx                                       r 0.5.11,5.11-0.133:20101027T183107Z
solaris   BRCMbnxe                                      r 0.5.11,5.11-0.133:20101027T183108Z
solaris   CPQary3                                       r 0.5.11,5.11-0.133:20101027T183108Z
solaris   FSWfontconfig-devel-docs                      o 0.5.11,5.11-0.130:20101027T183140Z
solaris   FSWxorg-client-docs                           r 0.5.11,5.11-0.130:20101027T183141Z
solaris   FSWxorg-client-programs                       r 0.5.11,5.11-0.130:20101027T183142Z
solaris   FSWxorg-clientlibs                            r 0.5.11,5.11-0.130:20101027T183142Z
solaris   FSWxorg-data                                  r 0.5.11,5.11-0.130:20101027T183143Z 


Checking the local repository packages status and updated dates
root@unixrock:~# pkgrepo info -s /unixrepo/repo/repo
PUBLISHER PACKAGES STATUS           UPDATED
solaris   4299     online           2014-08-14T17:34:29.002068Z
root@unixrock:~#
Checking the oracle repo packages status and updated dates.
root@unixrock:~# pkgrepo info -s http://pkg.oracle.com/solaris/release/
PUBLISHER PACKAGES STATUS           UPDATED
solaris   4870     online           2014-08-04T15:04:42.642929Z
root@unixrock:~#

Refreshing the local repository whenever its required
root@unixrock:~# pkgrepo refresh -s /unixrepo/repo/repo
Initiating repository refresh. 

Display All Repository Properties
root@unixrock:~# pkgrepo get -s /unixrepo/repo/repo
SECTION    PROPERTY    VALUE
publisher  prefix      solaris
repository description This\ repository\ serves\ a\ copy\ of\ the\ Oracle\ Solaris\ 11\ Build\ 175b\ Package\ Repository.
repository name        Oracle\ Solaris\ 11\ Build\ 175b\ Package\ Repository
repository version     4
root@unixrock:~#

Updating the local repository from Oracle Portal
root@unixrock:~# pkgrecv -s http://pkg.oracle.com/solaris/release -d /unixrepo/repo/repo solaris
Processing packages for publisher solaris ...
Retrieving and evaluating 4870 package(s)...
PROCESS                                         ITEMS    GET (MB)   SEND (MB)
SUNWamt                                        0/2016      0/7768     0/25461

Receiving single package on the local repository from Oracle Portal
root@unixrock:~# pkgrecv -s http://pkg.oracle.com/solaris/release/ -d /unixrepo/repo/repo pkg://solaris/diagnostic/tcpdump@4.1.1,5.11-0.175.1.0.0.24.0:20120904T171758Z
Processing packages for publisher solaris ...
Retrieving and evaluating 1 package(s)...
PROCESS                                         ITEMS    GET (MB)   SEND (MB)
Completed                                         1/1     0.8/0.8     2.2/2.2
root@unixrock:~#

Updating local respository with using latest SRU ( Solaris Repository Update images)
root@unixrock:/# lofiadm -a /var/tmp/sol-11_1_s11_sru11.4b.-x86.iso
/dev/lofi/1
root@unixrock:/# mount -F hsfs /dev/lofi/1 /mnt/repo
root@unixrock:/#
root@unixrock:/# df -h /mnt/repo
Filesystem             Size   Used  Available Capacity  Mounted on
/dev/lofi/1            357M   357M         0K   100%    /mnt/repo
root@unixrock:/#
root@unixrock:/# pkg publisher
PUBLISHER                   TYPE     STATUS P LOCATION
solaris                     origin   online F file:///unixrepo/repo/repo/
root@unixrock:/#
root@unixrock:/# pkgrecv -s /mnt/repo/repo -d /unixrepo/repo/repo/ "*"
Processing packages for publisher solaris ...
Retrieving and evaluating 4292 package(s)...
PROCESS                                         ITEMS    GET (MB)   SEND (MB)
Completed                                         1/1     0.0/0.0     0.0/0.0
root@unixrock:/#
root@unixrock:/# pkgrepo rebuild -s /unixrepo/repo/repo/
Initiating repository rebuild.
root@unixrock:/#
root@unixrock:/# svcprop -p pkg/inst_root svc:/application/pkg/server:default
/unixrepo/repo/repo
root@unixrock:/# svcadm restart svc:/application/pkg/server
root@unixrock:/#

Removing the package from local repository
root@unixrock:~# pkgrepo remove -p solaris -s /unixrepo/repo/repo/ pkg://solaris/diagnostic/tcpdump@4.1.1,5.11-0.175.1.0.0.24.0:20120904T171758Z
Removing packages for publisher solaris ...
PHASE                                          ITEMS
Deleting search index                           Done
Updating catalog                                Done
Analyzing removed packages                       1/1
Analyzing repository packages              4619/4619
Removing package manifests                       1/1
root@unixrock:~#

Verifying the package and found ERROR status
root@unixrock:~# pkg verify -v gzip
PACKAGE                                                                 STATUS
pkg://solaris/compress/gzip                                              ERROR
        file: usr/bin/gzip
                Mode: 01600 should be 0555
                Unexpected Exception: Request error: class file/memory mismatch
root@unixrock:~#
root@unixrock:~#

Fixing the package issue.
root@unixrock:~# pkg fix gzip
Verifying: pkg://solaris/compress/gzip                          ERROR
        file: usr/bin/gzip
                Mode: 01600 should be 0555
                Unexpected Exception: Request error: class file/memory mismatch
Created ZFS snapshot: 2014-08-15-17:56:18
Repairing: pkg://solaris/compress/gzip
Creating Plan (Evaluating mediators): -

DOWNLOAD                                PKGS         FILES    XFER (MB)   SPEED
Completed                                1/1           1/1      0.1/0.1    0B/s

PHASE                                          ITEMS
Updating modified actions                        1/1
Updating image state                            Done
Creating fast lookup database                   Done
root@unixrock:~#
root@unixrock:~# pkg verify -v gzip
PACKAGE                                                                 STATUS
pkg://solaris/compress/gzip                                                 OK
root@unixrock:~#

Cool !!!! Thanks for reading this post. Please leave your valuable comments and queries, I will get back to you as much I can. 

Solaris 11 - Network Administration / Link Aggregation / IPMP


Last post we have gone through some basic of Network administration, In this post we will be targeting some Advance features of Network administrations as like Link Aggregation, IPMP (IP Multipathing) features. Before going in deep we can see some basic concept of networking.

Basic Concepts :
  • Bandwidth : Bandwidth is bit rate for sending and receiving data over the network.
  • Failover     : Capability to have a backup component for the one becomes unavailable.
  • Load balancing : Distribution of workload to achieve best utilization.   
Link Aggregation:
Link Aggregation is combination of two or three physical interface on the system which are consider as a single logical unit (aggr) that provides best bandwidth, automatic fail over features, load balancing and redundancy benefits. Link Aggregation's Link should be in same Speed and same mode. We can administrate the link aggregation with using dladm command by adding, modifying, deleting links.


Before starting the aggregation, we have to make it sure physical interface should be have same mode as full-duplex  and same speed. By executing dladm show-link 

Creating aggregartion link with using two interface net1 and net2
root@unixrock:~# dladm create-aggr -l net1 -l net2 aggr0
root@unixrock:~#
root@unixrock:~# dladm show-link
LINK                CLASS     MTU    STATE    OVER
net0                phys      1500   up       --
net1                phys      1500   up       --
net3                phys      1500   up       --
net2                phys      1500   up       --
aggr0               aggr      1500   up       net1 net2
root@unixrock:~#
root@unixrock:~# dladm show-aggr
LINK              MODE  POLICY   ADDRPOLICY           LACPACTIVITY LACPTIMER
aggr0             trunk L4       auto                 off          short
root@unixrock:~#
To Add a another Link (net3) to an Aggregation (aggr0)
root@unixrock:~# dladm add-aggr -l net3 aggr0
root@unixrock:~# dladm show-link
LINK                CLASS     MTU    STATE    OVER
net0                phys      1500   up       --
net1                phys      1500   up       --
net3                phys      1500   up       --
net2                phys      1500   up       --
aggr0               aggr      1500   up       net1 net2 net3
root@unixrock:~#
To assigning IP to the aggregation link
root@unixrock:~# ipadm create-addr -T static -a 192.168.113.142 aggr0
ipadm: cannot create address: No such interface
root@unixrock:~#

Opps......getting error says that No such interface, that means we have to probe the interface first
root@unixrock:~# ipadm create-ip aggr0
root@unixrock:~# ipadm create-addr -T static -a 192.168.113.142 aggr0
aggr0/v4
root@unixrock:~#
Yes...we have done the aggr0 aggregation link with using net1 net2 net3 physical link and assigned Ip address too.
root@unixrock:~# dladm show-link
LINK                CLASS     MTU    STATE    OVER
net0                phys      1500   up       --
net1                phys      1500   up       --
net3                phys      1500   up       --
net2                phys      1500   up       --
aggr0               aggr      1500   up       net1 net2 net3
root@unixrock:~#
root@unixrock:~# ipadm show-addr
ADDROBJ           TYPE     STATE        ADDR
lo0/v4            static   ok           127.0.0.1/8
net0/v4test       static   ok           192.168.113.139/24
aggr0/v4          static   ok           192.168.113.142/24
lo0/v6            static   ok           ::1/128
root@unixrock:~#
To delete/remove the link from an Aggregation link
root@unixrock:~# dladm show-link
LINK                CLASS     MTU    STATE    OVER
net0                phys      1500   up       --
net1                phys      1500   up       --
net3                phys      1500   up       --
net2                phys      1500   up       --
aggr0               aggr      1500   up       net1 net2 net3
root@unixrock:~# dladm remove-aggr -l net3 aggr0
root@unixrock:~#
root@unixrock:~# dladm show-link
LINK                CLASS     MTU    STATE    OVER
net0                phys      1500   up       --
net1                phys      1500   up       --
net3                phys      1500   unknown  --
net2                phys      1500   up       --
aggr0               aggr      1500   up       net1 net2
root@unixrock:~#
IP Multipathing (IPMP)
IP Multipathing (IPMP) provides physical interface failure detection, Load balancing of packets, and transparent redundancy  features. IPMP which makes possible to assign the IP address to a group of network interface. if any one of the interface fails, the group can bind the IP address to another interface from the same IPMP group as transparent redundancy. IPMP can be configured for both IPv4 and IPv6. IPMP group will come up with ACTIVE - ACTIVE and ACTIVE- STANDBY
Advantage of IPMP
  • Fault tolerance
  • Spreading the load
  • Increased bandwidth
  • Transparent redundancy
  • Works even if its different switches
Components of IPMP
  • IPMP daemon : in.mapthd
  • IPMP service : svc:/network/ipmp:default
  • IPMP conf file : /etc/default/mpathd
  • IPMP Commands : ipadm, ipmpstat
Let we start Creating an IPMP group and Adding IP address to an IPMP group and Deleting and disable the IPMP group.
Creating ipmp0 group with using "ipadm create-ipmp" command
root@unixrock:/# 
root@unixrock:/# ipadm create-ip net1
root@unixrock:/# ipadm create-ip net2
root@unixrock:/# ipadm create-ip net3
root@unixrock:/# ipadm create-ipmp ipmp0
root@unixrock:/# ipadm add-ipmp -i net1 -i net3 ipmp0
root@unixrock:/# ipmpstat -g
GROUP       GROUPNAME   STATE     FDT       INTERFACES
ipmp0       ipmp0       ok        --        net3 net1
root@unixrock:/#
Assigning IP to that ipmp0 group
root@unixrock:~# ipadm create-addr -T static -a 192.168.113.145 ipmp0/v4addr1
root@unixrock:~# ipadm create-addr -T static -a 192.168.113.146 ipmp0/v4addr2
root@unixrock:~# ipadm show-addr
ADDROBJ           TYPE     STATE        ADDR
lo0/v4            static   ok           127.0.0.1/8
net0/v4test       static   ok           192.168.113.139/24
ipmp0/v4addr1     static   ok           192.168.113.145/24
ipmp0/v4addr2     static   ok           192.168.113.146/24
lo0/v6            static   ok           ::1/128
root@unixrock:~#
Remove the interface from IPMP group
root@unixrock:~# ipmpstat -g
GROUP       GROUPNAME   STATE     FDT       INTERFACES
ipmp0       ipmp0       ok        --        net1 net3
root@unixrock:~#
root@unixrock:~# ipadm remove-ipmp -i net1 ipmp0
root@unixrock:~# ipmpstat -g
GROUP       GROUPNAME   STATE     FDT       INTERFACES
ipmp0       ipmp0       ok        --        net3 
root@unixrock:~#
Adding one Interface to the IPMP group
root@unixrock:~# ipmpstat -g
GROUP       GROUPNAME   STATE     FDT       INTERFACES
ipmp0       ipmp0       ok        --        net3
root@unixrock:~# ipadm add-ipmp -i net2 ipmp0
root@unixrock:~# ipmpstat -g
GROUP       GROUPNAME   STATE     FDT       INTERFACES
ipmp0       ipmp0       ok        --        net2 net3
root@unixrock:~#
To disable an IPMP group
root@unixrock:~# ipadm disable-if -t ipmp0
root@unixrock:~# ipmpstat -g
root@unixrock:~# ipadm show-addr
ADDROBJ           TYPE     STATE        ADDR
lo0/v4            static   ok           127.0.0.1/8
net0/v4test       static   ok           192.168.113.139/24
lo0/v6            static   ok           ::1/128
ipmp0/v4addr1     static   disabled     192.168.113.145
ipmp0/v4addr2     static   disabled     192.168.113.146
root@unixrock:~#
To delete the IPMP group
root@unixrock:~# ipadm delete-ipmp ipmp0
root@unixrock:~# ipadm show-addr
ADDROBJ           TYPE     STATE        ADDR
lo0/v4            static   ok           127.0.0.1/8
net0/v4test       static   ok           192.168.113.139/24
lo0/v6            static   ok           ::1/128
root@unixrock:~#
Encountered some issues and fixes
ERROR : ipadm: cannot delete IPMP interface ipmp0: IPMP group is not empty
root@unixrock:~# ipadm delete-ipmp ipmp0
ipadm: cannot delete IPMP interface ipmp0: IPMP group is not empty
root@unixrock:~#
root@unixrock:~# ipmpstat -g
GROUP       GROUPNAME   STATE     FDT       INTERFACES
ipmp0       ipmp0       ok        --        net1
root@unixrock:~# ipmpstat -i
INTERFACE   ACTIVE  GROUP       FLAGS     LINK      PROBE     STATE
net1        yes     ipmp0       --mbM--   up        disabled  ok
root@unixrock:~# ipadm delete-ip net1
root@unixrock:~# ipadm delete-ipmp ipmp0
root@unixrock:~# ipadm show-if
IFNAME     CLASS    STATE    ACTIVE OVER
lo0        loopback ok       yes    --
net0       ip       ok       yes    --
net3       ip       disabled no     --
net2       ip       disabled no     --
root@unixrock:~#
ERROR: ipadm: cannot create interface net2: Operation not supported on disabled object 
ERROR: ipadm: persistent operation not supported for enable-if
root@unixrock:~# ipadm create-ip net2
ipadm: cannot create interface net2: Operation not supported on disabled object
root@unixrock:~#
root@unixrock:~# ipadm show-if
IFNAME     CLASS    STATE    ACTIVE OVER
lo0        loopback ok       yes    --
net0       ip       ok       yes    --
net3       ip       disabled no     --
net2       ip       disabled no     --
root@unixrock:~# 
root@unixrock:~# ipadm enable-if net3
ipadm: persistent operation not supported for enable-if
root@unixrock:~# 
root@unixrock:~# ipadm enable-if -t net3
root@unixrock:~# ipadm enable-if -t net2
root@unixrock:~#
root@unixrock:~# ipadm show-if
IFNAME     CLASS    STATE    ACTIVE OVER
lo0        loopback ok       yes    --
net0       ip       ok       yes    --
net2       ip       down     no     --
net3       ip       down     no     --
root@unixrock:~#
Thanks for reading this post. Please leave your valuable comments and queries, I will get back to you at earliest possible. 

LDOM Interview Questions and Answers


Please Refer LDOM Quick Reference Guide 
 
 
1. How to check the Version of Logical Domain Manager and Hypervisor ?
# ldm -V     Display version information of LDM and Hypervisor
 
2. Brief about Primary/Control Domain ?
 
It Controls the Oracle VM and also called as Primary domain.
  • Used to configure server resources and guest domains and Provides virtual console services.
  • Logical domain Manager installed only on Control domain.
  • Control domain normally act as Service domain.
  • For more reference "How to Configure Primary or Control Domain." 


  • 3. Brief about Service Domain?
    Service domain Provides virtual device services to Guest Domain.
  • It provides Virtual Disk Services.
  • It provides Virtual Console Services.
  • It provides Virtual network Switches.
  • For more reference "How to Configure Service Domain"

  • 4. Brief about Guest/Logical Domain?
     Guest domain uses only virtual services.
    • Guest domain where our OS is installed.
    • Get the services from service domain in order to run application and user services.
    • Guest domain can be a I/O Domain.
    • For more reference "How to Configure Logical/Guest Domain"

    5. Brief about I/O domain ?
    • I/O Domain where we are getting phyiscal I/O device access directly.
    • I/O device which connects PCI bus, such as local network interface, disk drives and PCI adapters.
    • For more reference "How to Configure I/O Domain"
    6. How to check the list of services ?

    List the Virtual services currently configure in the Control Domain
    Syntax : # ldm list-services  [-e] [-p] [...]
    # ldm list-services primary

    7. How to backup the LDOM configuration and how to restore?

    Syntax : # ldm list-constraints ([-x] | [-e] [-p]) [...]
    # ldm list-constraints -p
    VERSION 1.5
    DOMAIN|name=primary
    UUID|uuid=f44b4e9e-330c-4a20-c22e-a18c1c6f61b1
    MAC|mac-addr=00:14:4f:82:5c:ee
    CONTROL|failure-policy=ignore
    CORE|count=2
    VCPU|count=8
    MAU|count=1
    MEMORY|size=2147483648
    VARIABLES
    |keyboard-layout=US-English
    IO
    |dev=pci@780|alias=
    |dev=pci@7c0|alias=
    VCC|name=primary-vcc0|port-range=5000-5100
    VSW|name=primary-vsw0|mac-addr=|net-dev=e1000g0|dev=switch@0|default-vlan-id=1|pvid=1|vid=|mode=|mtu=|linkprop=|id=0
    VDS|name=primary-vds0
    [root@unixrock /]#
    [root@unixrock /]# ldm list-constraints -x primary > /unixrock.xml
    [root@unixrock /]# file /unixrock.xml
    primary.xml:    XML document
    [root@unixrock /]# ls -l /unixrock.xml
    -rw-r--r--   1 root     root        3988 Feb 17 14:26 unixrock.xml
    [root@unixrock /]#

    To restore the configuration NOTE: System configuration should be Factory-default setting

    [root@unixrock /]# ldm list-spconfig
    factory-default (current)
    [root@unixrock /]# ldm init-system -i /unixrock.xml
    [root@unixrock /]# ldm add-spconfig unixrock_config
    [root@unixrock /]# ldm list-spconfig
    factory-default
    unixrock_config (current)
    [root@unixrock /]#

    8. How to check the list of available devices ?

    Syntax : # ldm list-devices [-a] [-p] [core] [cpu] [crypto|mau] [memory] [io] 
    Example : # ldm list-devices -a               To list all the host server resources details
    Example : # ldm list-devices -a cpu         To list all the host server CPU resources 
    Example : # ldm list-devices -a memory To list all the host server MEMORY resources 
    Example : # ldm list-devices -a io            To list all the host server I/O resources
    9. How to add and remove the LDOM ?

    Syntax :  # ldm  list-domain [-e] [-l] [-o ] [-p] [...]
    Syntax :  # ldm add-domain (-i |[mac-addr=] [hostid=][failure-policy=][master=] ...)
    Syntax :  # ldm remove-domain (-a | ...)

    [root@unixrock /]# ldm list-domain
    NAME             STATE      FLAGS   CONS    VCPU  MEMORY   UTIL  UPTIME
    primary          active     -n-cv-  SP      8     8G       0.4%  4h 7m
    [root@unixrock /]#
    [root@unixrock /]# ldm add-domain rockldom1
    [root@unixrock /]# ldm list-domain
    [root@unixrock /]#
    NAME             STATE      FLAGS   CONS    VCPU  MEMORY   UTIL  UPTIME
    primary          active     -n-cv-  SP      8     8G       0.4%  4h 7m
    rockldom1       inactive    ------ 
    [root@unixrock /]#
    [root@unixrock /]# ldm remove-domain rockldom1
    [root@unixrock /]#


    10. How to start and stop the LDOM ?

    Syntax :- ldm start-domain (-a | -i | ...) 
    Syntax :- ldm stop-domain [-f] (-a | ...)
    [root@unixrock /]# ldm start-domain rockldom1
    LDom rockldom1 started
    [root@unixrock /]# ldm stop-domain rockldom1
    LDom rockldom1 stopped
    [root@unixrock /]# 

    11. How to migrate the LDOM to another Host?

    NOTE: Source and Target service configuration should be same.
    Syntax :- # ldm migrate-domain [-f] [-n] [-p ] [@][:]
    [root@unixrock /]# ldm migrate-domain ldom1 root@192.168.10.25 
    Target Password:

    12. How to add/set the Memory resources to the LDOM ?

    To add the memory to the guest domain
    Syntax : # ldm add-memory [--auto-adj] [GMK]
               Example : # ldm add-memory 2G ldom1 
    To reconfigure the memory to the guest or primary domain
    Syntax : # ldm set-memory [--auto-adj] [GMK]
               Example : # ldm set-memory 5G primary 
               Example : # ldm set-memory 2G ldom1 
    To decrease the amount of memory in a domain
    Syntax : # ldm remove-memory [--auto-adj] [GMK]
                Example : # ldm remove-memory 1G primary 
                Example : # ldm remove-memory 1024M ldom1

    13. How to dump the configuration to the SP ?
    Syntax : # ldm list-spconfig [-r []]

                 Example : # ldm list-spconfig 
    Syntax : # ldm add-spconfig [-r ]
                 Example : # ldm add-spconfig config_initial 
    Syntax : # ldm remove-spconfig [-r]
                 Example : # ldm remove-spconfig config_initial 

    [root@unixrock /]# ldm list-spconfig
    factory-default
    tempprofile [current]
    [root@unixrock /]# ldm remove-spconfig tempprofile
    [root@unixrock /]# ldm list-spconfig
    factory-default [next poweron]
    [root@unixrock /]# ldm add-spconfig config_intial
    [root@unixrock /]# ldm list-spconfig
    factory-default
    config_intial [current]
    [root@unixrock /]#
    [root@unixrock /]# 


    14. How to set the LDOM variables ?

    To list the Variable settings of guest domain
    Syntax : # ldm list-variable [...]
           Example : # ldm list-variable auto-boot\? Ldom1
           Example : # ldm list-variable boot-device Ldom1
    To add the new variable setting to the guest domain
    Syntax : # ldm add-variable =...
           Example : # ldm add-variable boot-device Ldom1
    To set the "auto-boot" variable as false, this will leave the server at in OK prompt 
    Syntax : # ldm  set-variable =...
           Example : # ldm set-variable auto-boot\?=false Ldom1

    15. How to add the VCC on primary domain ?

    To add the Virtual console concentrator service to the control domain
    Syntax : # ldm add-vconscon port-range=-
          Example : # ldm add-vconscon port-range=5000-5100 primary-vcc0 primary
    To set or modify the Virtual console concentrator service to the control domain
    Syntax : # ldm set-vconscon port-range=-
          Example : # ldm set-vconscon port-range=5000-5100 primary-vcc0
    To remove the Virtual console service from domain
    Syntax : # ldm remove-vconscon [-f]
          Example : # ldm remove-vconscon primary-vcc0


    16. How to add/set/remove the virtual CPU to the domain?

    To add CPU to the guest domain
    Syntax : # ldm add-vcpu [-c|--core]
         Example : # ldm add-vpcu 8 ldom1
    To reconfigure the virtual CPU for any domain 
    Syntax : # ldm set-vcpu [-c|--core]
         Example : # ldm set-vpcu 10 primary
    To decrease the number of virtual CPU for any domain 
    Syntax : # ldm remove-vcpu [-f|--force] [-c|--core]
         Example : # ldm remove-vpcu 2 ldom1

    17. How to add/remove the Virtual disk to the domain?


    To assign the Virual disk to the guest domain
    Syntax :# ldm add-vdisk [timeout=] [id=]    @
          Example : # ldm add-vdisk vdisk0 vol0@primary-vds0 ldom1
          Example : # ldm add-vdisk iso01 iso01@primary-vds0 ldom1
    To remove the  Virual disk  on the guest domain
    Syntax :# ldm remove-vdisk [-f]
          Example : # ldm remove-vdisk vdisk0 ldom1

    18. How to add/remove the ISO image to the domain?
    To add or associating the iso resources to the Control domain's virtual disk services 
     

    [root@unixrock /]# ldm add-vdsdev options=ro /export/home/solaris.iso iso01@primary-vds0
    [root@unixrock /]#
    To remove Virtual disk server devices
    [root@unixrock /]# ldm remove-vdsdev iso01@primary-vds0
    [root@unixrock /]#

    19. How to add the vds services to the domain?

    To add the Virtual disk Server services
    Syntax : # ldm add-vdiskserver
           Example : # ldm add-vdiskserver primary-vds0 primary
           Example : # ldm add-vds primary-vds0 primary
    To remove the Virtual disk Server services
    Syntax : # ldm remove-vdiskserver [-f]
           Example : # ldm remove-vds primary-vds0

    20. How to add/remove Virtual Network services LDOM ?

    To add virtual network device which is associated with the virtual switch  to the guest domain
    Syntax : # ldm add-vnet [mac-addr=] [mode=hybrid] [pvid=] [vid=] [mtu=] [linkprop=phys-state][id=]
           Example : # ldm  add-vnet vnet0 primary-vsw0 ldom1
    To remove the Virtual network device
    Syntax : # ldm remove-vnet [-f]
           Example : # ldm  remove-vnet vnet0  ldom1
     
    21. How to add/remove Virtual Switch on the domain ?

    To add the virtual switch services 
    Syntax : # ldm  add-vswitch [default-vlan-id=] [pvid=] [vid=][mac-addr=] [net-dev=] [linkprop=phys-state][mode=] [mtu=] [id=]
           Example : # ldm add-vswitch net-dev=e1000g0 primary-vsw0 primary
    To remove the virtual switch services
    Syntax : # ldm remove-vswitch [-f]
           Example : # ldm remove-vswitch primary-vsw0 

    22. How to add/remove Virtual disk server device (vdsdev) ?

    To add or associating the resources to the Control domain's virtual disk services
    Syntax : # ldm add-vdiskserverdevice [-f] [options={ro,slice,excl}] [mpgroup=] @
          Example : # ldm add-vdsdev /dev/dsk/c0t1d0s2 vol01@primary-vds0
          Example : # ldm add-vdsdev options=ro /export/home/solaris.iso iso01@primary-vds0
    To remove Virtual disk server devices
    Syntax : # ldm  remove-vdiskserverdevice [-f] @
          Example : # ldm remove-vdsdev vol01@primary-vds0
          Example : # ldm remove-vdsdev iso01@primary-vds0

    Thanks for reading this post.....Please leave your valuable comments or queries, will get back to you at earliest 
     
     

    Solaris 11 - Basic of Network Administration

    Especially network changes is one of the main concern in Solaris 11. Significant development in network side when we comparing with Solaris 10. Solaris 11 comes with profile-based network configurations which contains manual (Fixed Network configuration profile - NCP) and Automatic (reactive-Network Configuration profile - NCP) modes. Also introduced Network Auto-Magic (NWAM) features.

    :~# netadm list
    TYPE        PROFILE        STATE
    ncp         Automatic      online
    ncu:phys    net0           online
    ncu:phys    net1           online
    ncu:phys    net3           online
    ncu:phys    net2           online
    ncu:ip      net0           online
    ncu:ip      net1           online
    ncu:ip      net3           online
    ncu:ip      net2           online
    ncp         DefaultFixed   disabled
    loc         DefaultFixed   offline
    loc         Automatic      online
    loc         NoNet          offline

    Showing the phyiscal interface
    root@unixrock:~# dladm show-phys
    LINK              MEDIA                STATE      SPEED  DUPLEX    DEVICE
    net0              Ethernet             up         1000   full      e1000g0
    net1              Ethernet             up         1000   full      e1000g1
    net3              Ethernet             up         1000   full      e1000g3
    net2              Ethernet             up         1000   full      e1000g2
    root@unixrock:~# 

    Showing the Link status of the physical interface
    root@unixrock:~# dladm show-link
    LINK                CLASS     MTU    STATE    OVER
    net0                phys      1500   up       --
    net1                phys      1500   up       --
    net3                phys      1500   up       --
    net2                phys      1500   up       --
    root@unixrock:~#

    checking existing interface on the system
    root@unixrock:~# ipadm show-if
    IFNAME     CLASS    STATE    ACTIVE OVER
    lo0        loopback ok       yes    --
    net0       ip       ok       yes    --
    net1       ip       ok       yes    --
    net2       ip       ok       yes    --
    net3       ip       ok       yes    --
    root@unixrock:~#

    checking MAC address and IP address
    root@unixrock:~# ipadm show-addr
    ADDROBJ           TYPE     STATE        ADDR
    lo0/v4            static   ok           127.0.0.1/8
    net0/v4           dhcp     ok           192.168.113.139/24
    net1/v4           dhcp     ok           192.168.113.141/24
    net2/v4           dhcp     ok           192.168.113.143/24
    net3/v4           dhcp     ok           192.168.113.142/24
    lo0/v6            static   ok           ::1/128
    net0/v6           addrconf ok           fe80::20c:29ff:febf:ac5b/10
    net1/v6           addrconf ok           fe80::20c:29ff:febf:ac65/10
    net2/v6           addrconf ok           fe80::20c:29ff:febf:ac6f/10
    net3/v6           addrconf ok           fe80::20c:29ff:febf:ac79/10
    root@unixrock:~#

    root@unixrock:~# dladm show-phys
    LINK              MEDIA           STATE      SPEED  DUPLEX  DEVICE
    net0              Ethernet       UNKNOWN      1000   full   e1000g0
    net1              Ethernet       UNKNOWN      1000   full   e1000g1
    net3              Ethernet       UNKNOWN      1000   full   e1000g3
    net2              Ethernet       UNKNOWN      1000   full   e1000g2
    root@unixrock:~#
    root@unixrock:~# dladm show-link
    LINK                CLASS     MTU    STATE    OVER
    net0                phys      1500   UNKNOWN       --
    net1                phys      1500   UNKNOWN       --
    net3                phys      1500   UNKNOWN       --
    net2                phys      1500   UNKNOWN       --
    root@unixrock:~#
    root@unixrock:~# ipadm show-if
    IFNAME     CLASS    STATE    ACTIVE OVER
    lo0        loopback ok       yes    --
    root@unixrock:~#
    root@unixrock:~# ipadm show-addr

    Asssing IP Address to the net0 interface
    root@unixrock:~# ipadm create-addr -T static -a 192.168.113.139/24 net0/v4test
    root@unixrock:~#
    root@unixrock:~# ipadm show-if
    IFNAME     CLASS    STATE    ACTIVE OVER
    lo0        loopback ok       yes    --
    net0       ip       ok       yes    --
    root@unixrock:~# ipadm show-addr
    ADDROBJ           TYPE     STATE        ADDR
    lo0/v4            static   ok           127.0.0.1/8)
    net0/v4test       static   ok           192.168.113.139/24
    lo0/v6            static   ok           ::1/128
    root@unixrock:~#

    NOTE : "T" - option can be used for three specify interface mode static, DHCP and addrconf (auto configured IPV6 address) Trying DHCP for another interface net1
    root@unixrock:~#
    root@unixrock:~# ipadm create-ip net1
    root@unixrock:~# ipadm create-addr -T dhcp net1/v4test2
    root@unixrock:~# ipadm show-if
    IFNAME     CLASS    STATE    ACTIVE OVER
    lo0        loopback ok       yes    --
    net0       ip       ok       yes    --
    net1       ip       ok       yes    --
    root@unixrock:~# ipadm show-addr
    ADDROBJ           TYPE     STATE        ADDR
    lo0/v4            static   ok           127.0.0.1/8
    net0/v4test       static   ok           192.168.113.139/24
    net1/v4test2      dhcp     ok           192.168.113.141/24
    lo0/v6            static   ok           ::1/128
    root@unixrock:~#

    If you want to change the IP, then we need to delete and recreate the interface with new IP. Let we change the IP address
    root@unixrock:~# ipadm delete-ip net2
    root@unixrock:~# ipadm create-ip net2
    root@unixrock:~# ipadm create-addr -T static -a 192.168.113.140 net2/v4test1
    root@unixrock:~# ipadm show-addr
    ADDROBJ           TYPE     STATE        ADDR
    lo0/v4            static   ok           127.0.0.1/8
    net0/v4test       static   ok           192.168.113.139/24
    net1/v4test2      dhcp     ok           192.168.113.141/24
    net2/v4test1      static   ok           192.168.113.140/24
    lo0/v6            static   ok           ::1/128
    root@unixrock:~#

    Wednesday, August 26, 2015

    bashrc profile

    Bashrc Profile


    ~ # more .bashrc
    #!/usr/bin/bash
    #
    # Khan .bashrc file
    #
    AWK=/usr/xpg4/bin/awk
    CUT=/usr/bin/cut
    DATE=/usr/bin/date
    #echo start dot bashrc
    #-----------------------
    # Greeting, motd etc...
    #-----------------------
    # Define some colors first:
    red='\e[0;31m'
    RED='\e[1;31m'
    blue='\e[0;34m'
    BLUE='\e[1;34m'
    cyan='\e[0;36m'
    CYAN='\e[1;36m'
    NC='\e[0m'              # No Color
    settitle ()
    {
           _whereme=${_whereme:="`hostname`"}
           _whome=${_whome:="`id |${CUT} -d '(' -f2|${CUT} -d ')' -f1' '`"}
              echo -e "\033]2;$_whome@$_whereme:$PWD\007\c"
    }
    telnet ()
    {
        if [ -n "$STY" -a -n "$1" ]; then
            screen -T xterm -t "$1" //telnet "$@";
        else
            /usr/bin/telnet "$@";
        fi
    }
    #ssh ()
    #{
    #    if [ -n "$STY" -a -n "$1" ]; then
    #        local _HOSTNAME;
    #        _HOSTNAME=$( eval echo \$$# );
    #        /usr/bin/echo "\033]83;screen -t "$_HOSTNAME" ssh $@\007\c";
    #    else
    #        /usr/bin/ssh "$@";
    #    fi
    #}
    #
    # checking if SU to root, if so source profile to get path
    #
    export ID=` id | ${CUT} -f2 -d"(" | ${CUT} -f1 -d")"`
    if [ ${ID} == "root" ]; then
            if [ -f /root/.profile-EIS ]
            then
                    echo aquiring root profile
            . /root/.profile-EIS
            fi
    fi
    if [ -d /usr/local/bin ]
    then
            PATH=/usr/local/bin:/usr/local/sbin:${PATH}:/usr/xpg4/bin
    #        PATH=/usr/xpg4/bin:/usr/local/bin:${PATH}
            MANPATH=${MANPATH}:/usr/local/man
    fi
    if [ -d /home/abrook/bin ]
    then
    #        PATH=${PATH}:/home/abrook/bin
            PATH=/home/abrook/bin:${PATH}
            MANPATH=${MANPATH}:/home/abrook/man
    fi
    if [ -d /usr/perl5/bin ]
    then
            PATH=${PATH}:/usr/perl5/bin
            MANPATH=/usr/perl5/man:${MANPATH}
    fi
    if [ -d /opt/webstack/mysql/bin ]
    then
            PATH=${PATH}:/opt/webstack/mysql/bin
            MANPATH=//opt/webstack/mysql/man:${MANPATH}
    fi

    if [ -f /etc/zones/index ]
    then
            export ZONENAME=`cat /etc/zones/index | grep -v "^#" | head -1 | awk -F\:  '{print $1}'`
    else
            export ZONENAME="No Zones "
    fi
    #export PS1='\# \u@\H \w \$ '
    export PS1="${BLUE}\# ${RED}\u@\h ${BLUE}\w \$ >${NC} "
    #PS1="${LOGNAME}@$(hostname):$(
    #    [[ "$LOGNAME" = "root" ]] && printf "${PWD/${HOME}/~}# " ||
    #    printf "${PWD/${HOME}/~}\$ ")'
    TIME=`${DATE} +%H:%M`
    if [ -f /root/server-name ]
    then
    servername=`cat /root/server-name`
    fi
    #export PS1="\# ${RED}${ZONENAME} ${BLUE}${LOGNAME}@$(hostname) $( [[ "$ID" = "root" ]] && printf " ${RED}\n\w # ${NC}\n" || printf " ${BLUE}\n\w $ ${NC}")"
    export PS1="\# ${servername} ${RED}${ZONENAME} ${BLUE}${LOGNAME}@$(hostname) $( [[ "$ID" = "root" ]] && printf " ${RED}\n\w # ${NC}\n" || printf " ${BLUE}\n\
    w $ ${NC}")"
    source /home/abrook/bin/hcmnt
    export hcmntextra='date "+%Y%m%d %R"'
    export PROMPT_COMMAND='hcmnt'
    PROMPT_COMMAND='hcmnt -etyl ~/.hcmnt.$(hostname).log $LOGNAME@$HOSTNAME'
    #export PROMPT_COMMAND=settitle
    #export PROMPT_COMMAND=settitle
    #if [ $(hostname)  == "abrook-desktop" ]; then
    #echo "setting default proxy"
    #echo "set default proxy"
    #fi
    #---------------
    # Some settings
    #---------------
    ulimit -S -c 0          # Don't want any coredumps
    set -o notify
    set -o ignoreeof
    set -o nounset
    #set -o xtrace          # useful for debuging
    # Enable options:
    shopt -s cdspell
    shopt -s cdable_vars
    shopt -s checkhash
    shopt -s checkwinsize
    shopt -s mailwarn
    shopt -s sourcepath
    shopt -s no_empty_cmd_completion  # bash>=2.04 only
    shopt -s cmdhist
    shopt -s histappend histreedit histverify
    shopt -s extglob        # necessary for programmable completion
    # Disable options:
    shopt -u mailwarn
    unset MAILCHECK         # I don't want my shell to warn me of incoming mail

    export TIMEFORMAT=$'\nreal %3R\tuser %3U\tsys %3S\tpcpu %P\n'
    export HISTIGNORE="&:bg:fg:ll:h"
    export HOSTFILE=$HOME/.hosts    # Put a list of remote hosts in ~/.hosts
    # fix timouts
    export TMOUT=0
    export TIMEOUT=0
    unset autologout


    #
    # Colour Codes
    #PS1='[\u@TEST \w]\n \#\$ \n\
    #\[\
    #\e[1mBold Text\e[m\n\
    #\e[4mUnderline Text\e[m\n\
    #\e[5mBlink Text\e[m\n\
    #\e[7mInverse Text\e[m\]\n\
    #Should be normal text
    #Foreground colors:
    #\[\
    #\e[0;30m30: Black\n\
    #\e[0;31m31: Red\n\
    #\e[0;32m32: Green\n\
    #\e[0;33m33: Yellow\Orange\n\
    #\e[0;34m34: Blue\n\
    #\e[0;35m35: Magenta\n\
    #\e[0;36m36: Cyan\n\
    #\e[0;37m37: Light Gray\Black\n\
    #\e[0;39m39: Default\n\
    #Bright foreground colors:
    #\e[1;30m30: Dark Gray\n\
    #\e[1;31m31: Red\n\
    #\e[1;32m32: Green\n\
    #\e[1;33m33: Yellow\n\
    #\e[1;34m34: Blue\n\
    #\e[1;35m35: Magenta\n\
    #\e[1;36m36: Cyan\n\
    #\e[1;37m37: White\n\
    #\e[0;39m39: Default\n\
    #\e[m\]Background colors:
    #\[\e[1;37m\e[40m40: Black\e[0;49m\n\
    #\e[41m41: Red\e[0;49m\n\
    #\e[42m42: Green\e[0;49m\n\
    #\e[43m43: Yellow\Orange\e[0;49m\n\
    #\e[44m44: Blue\e[0;49m\n\
    #\e[45m45: Magenta\e[0;49m\n\
    #\e[46m46: Cyan\e[0;49m\n\
    #\e[47m47: Light Gray\Black\e[0;49m\n\
    #\e[49m49: Default\e[m\]\n'
    # Looks best on a black background.....
    #if [ -z ${DISPLAY:=""|} ]; then
    #echo -e "${BLUE}This is BASH ${RED}${BASH_VERSION%.*}${BLUE} - DISPLAY on ${RED}$DISPLAY${NC}\n"
    #else
    #echo -e "${BLUE}This is BASH ${RED}${BASH_VERSION%.*}${BLUE} ${NC}\n"
    #fi
    #date
    #if [ -x /usr/games/fortune ]; then
    #    /usr/games/fortune -s     # makes our day a bit more fun.... :-)
    #fi
    #function _exit()       # function to run upon exit of shell
    #{
    #    echo -e "${RED}Leaving Bash shell ${NC}"
    #}
    #trap _exit EXIT
    #---------------
    # Shell Prompt
    #---------------
    #  --> Replace instances of \W with \w in prompt functions below
    #+ --> to get display of full path name.
    #===============================================================
    #
    # ALIASES AND FUNCTIONS
    #
    # Arguably, some functions defined here are quite big
    # (ie 'lowercase') but my workstation has 512Meg of RAM, so .....
    # If you want to make this file smaller, these functions can
    # be converted into scripts.
    #
    # Many functions were taken (almost) straight from the bash-2.04
    # examples.
    #
    #===============================================================
    #-------------------
    # Personnal Aliases
    #-------------------
    # -> Prevents accidentally clobbering files.
    #alias rm='rm -i'
    alias cp='cp -i'
    alias sd='sudo /usr/bin/bash'
    alias mv='mv -i'
    # turns off noclober for all files
    #set +o noclobber
    alias mkdir='mkdir -p'
    alias j='jobs -l'
    alias which='type -all'
    alias ..='cd ..'
    alias path='echo -e ${PATH//:/\\n}'
    alias print='/usr/bin/lp -o nobanner -d $LPDEST'   # Assumes LPDEST is defined
    alias pjet='enscript -h -G -fCourier9 -d $LPDEST'  # Pretty-print using enscript
    alias du='du -kh'
    alias df='df -kh'
    # The 'ls' family (this assumes you use the GNU ls)
    alias la='ls -Al'               # show hidden files
    #alias ls='ls -hF --color'      # add colors for filetype recognition
    alias lx='ls -lXB'              # sort by extension
    alias lk='ls -lSr'              # sort by size
    alias lc='ls -lcr'              # sort by change time
    #alias lu='ls -lur'             # sort by access time
    alias lr='ls -lR'               # recursive ls
    alias lt='ls -ltr'              # sort by date
    alias lm='ls -al |more'         # pipe through 'more'
    alias tree='tree -Csu'          # nice alternative to 'ls'
    # tailoring 'less'
    alias more='less'
    export PAGER=less
    export LESSCHARSET='latin1'
    export LESSOPEN='|/usr/bin/lesspipe.sh %s 2>&-' # Use this if lesspipe.sh exists
    export LESS='-i -n -w  -z-4 -g -e -M -X -F -R -P%t?f%f \
    :stdin .?pb%pb\%:?lbLine %lb:?bbByte %bb:-...'
    # spelling typos - highly personnal :-)
    alias xs='cd'
    alias vf='cd'
    alias moer='more'
    alias moew='more'
    alias kk='ll'
    alias h='history | tail -20'
    #
    # setup profile aliases
    #
    for i in `/usr/bin/profiles -l | grep -v ":$" | grep -v '*' | sed 's/^[ \t] *//' | grep "^/.*" | ${CUT} -f1 -d " "`
    do
    alias `basename $i`="pfexec `basename $i`"
    done
    alias sur='su primaryadmin'
    #
    #
    #
    #alias tapewwn="luxadm -e dump_map `luxadm -e port | grep -v NOT | grep 60000 | ${AWK} '{print $1}'` | grep Tape | ${AWK} '{print $4}'"
    #alias tapewwn="luxadm -e port | grep -v NOT | grep 60000 | ${AWK} '{print $1}'"
    #-----------------------------------
    # File & strings related functions:
    #-----------------------------------
    # Find a file with a pattern in name:
    function ff() { find . -type f -iname '*'$*'*' -ls ; }
    # Find a file with pattern $1 in name and Exe/usr/bin/cute $2 on it:
    function fe() { find . -type f -iname '*'$1'*' -exec "${2:-file}" {} \;  ; }
    # find pattern in a set of filesand highlight them:
    function fstr()
    {
        OPTIND=1
        local case=""
        local usage="fstr: find string in files.
    Usage: fstr [-i] \"pattern\" [\"filename pattern\"] "
        while getopts :it opt
        do
            case "$opt" in
            i) case="-i " ;;
            *) echo "$usage"; return;;
            esac
        done
        shift $(( $OPTIND - 1 ))
        if [ "$#" -lt 1 ]; then
            echo "$usage"
            return;
        fi
        local SMSO=$(tput smso)
        local RMSO=$(tput rmso)
        find . -type f -name "${2:-*}" -print0 | xargs -0 grep -sn ${case} "$1" 2>&- | \
    sed "s/$1/${SMSO}\0${RMSO}/gI" | more
    }
    function cuttail() # /usr/bin/cut last n lines in file, 10 by default
    {
        nlines=${2:-10}
        sed -n -e :a -e "1,${nlines}!{P;N;D;};N;ba" $1
    }
    function lowercase()  # move filenames to lowercase
    {
        for file ; do
            filename=${file##*/}
            case "$filename" in
            */*) dirname==${file%/*} ;;
            *) dirname=.;;
            esac
            nf=$(echo $filename | tr A-Z a-z)
            newname="${dirname}/${nf}"
            if [ "$nf" != "$filename" ]; then
                mv "$file" "$newname"
                echo "lowercase: $file --> $newname"
            else
                echo "lowercase: $file not changed."
            fi
        done
    }
    function file-swap()         # swap 2 filenames around
    {
        local TMPFILE=tmp.$$
        mv "$1" $TMPFILE
        mv "$2" "$1"
        mv $TMPFILE "$2"
    }

    #-----------------------------------
    # Process/system related functions:
    #-----------------------------------
    #function my_ps() { ps $@ -u $USER -o pid,%cpu,%mem,bsdtime,command ; }
    #function pp() { my_ps f | ${AWK} '!/${AWK}/ && $0~var' var=${1:-".*"} ; }
    # This function is roughly the same as 'killall' on linux
    # but has no equivalent (that I know of) on Solaris
    function killps()   # kill by process name
    {
        local pid pname sig="-TERM"   # default signal
        if [ "$#" -lt 1 ] || [ "$#" -gt 2 ]; then
            echo "Usage: killps [-SIGNAL] pattern"
            return;
        fi
        if [ $# = 2 ]; then sig=$1 ; fi
        for pid in $(my_ps| ${AWK} '!/${AWK}/ && $0~pat { print $1 }' pat=${!#} ) ; do
            pname=$(my_ps | ${AWK} '$1~var { print $5 }' var=$pid )
            if ask "Kill process $pid <$pname> with signal $sig?"
                then kill $sig $pid
            fi
        done
    }
    function my_ip() # get IP adresses
    {
        MY_IP=$(/sbin/ifconfig -a | ${AWK} '/inet/ { print $2 } ' | sed -e s/addr://)
    }
    function ii()   # get current host related info
    {
        echo -e "\nYou are logged on ${RED}$_HOSTNAME"
        echo -e "\nAdditionnal information:$NC " ; uname -a
        echo -e "\n${RED}Users logged on:$NC " ; w -h
        echo -e "\n${RED}Current date :$NC " ; ${DATE}
        echo -e "\n${RED}Machine stats :$NC " ; uptime
        my_ip 2>&- ;
        echo -e "\n${RED}Local IP Address :$NC" ; echo ${MY_IP:-"Not connected"}
        echo
    }
    # Misc utilities:
    function repeat()       # repeat n times command
    {
        local i max
        max=$1; shift;
        for ((i=1; i <= max ; i++)); do  # --> C-like syntax
            eval "$@";
        done
    }
    function ask()
    {
        echo -n "$@" '[y/n] ' ; read ans
        case "$ans" in
            y*|Y*) return 0 ;;
            *) return 1 ;;
        esac
    }
    function change()
    {
    STAMP=`${DATE} +bak.%m-%d-%H-%M`
    cp $1 $1.${STAMP}
    vi $1
    }

    #=========================================================================
    #
    # PROGRAMMABLE COMPLETION - ONLY SINCE BASH-2.04
    # Most are taken from the bash 2.05 documentation and from Ian McDonalds
    # 'Bash completion' package (http://www.caliban.org/bash/index.shtml#completion)
    # You will in fact need bash-2.05a for some features
    #
    #=========================================================================
    if [ "${BASH_VERSION%.*}" \< "2.05" ]; then
        echo "You will need to upgrade to version 2.05 for programmable completion"
        return
    fi
    shopt -s extglob        # necessary
    set +o nounset          # otherwise some completions will fail
    complete -A hostname   rsh rcp telnet rlogin r ftp ping disk
    complete -A export     printenv
    complete -A variable   export local readonly unset
    complete -A enabled    builtin
    complete -A alias      alias unalias
    complete -A function   function
    complete -A user       su mail finger
    complete -A helptopic  help     # currently same as builtins
    complete -A shopt      shopt
    complete -A stopped -P '%' bg
    complete -A job -P '%'     fg jobs disown
    complete -A directory  mkdir rmdir
    complete -A directory   -o default cd
    # Compression
    complete -f -o default -X '*.+(zip|ZIP)'  zip
    complete -f -o default -X '!*.+(zip|ZIP)' unzip
    complete -f -o default -X '*.+(z|Z)'      compress
    complete -f -o default -X '!*.+(z|Z)'     uncompress
    complete -f -o default -X '*.+(gz|GZ)'    gzip
    complete -f -o default -X '!*.+(gz|GZ)'   gunzip
    complete -f -o default -X '*.+(bz2|BZ2)'  bzip2
    complete -f -o default -X '!*.+(bz2|BZ2)' bunzip2
    # Postscript,pdf,dvi.....
    complete -f -o default -X '!*.ps'  gs ghostview ps2pdf ps2ascii
    complete -f -o default -X '!*.dvi' dvips dvipdf xdvi dviselect dvitype
    complete -f -o default -X '!*.pdf' acroread pdf2ps
    complete -f -o default -X '!*.+(pdf|ps)' gv
    complete -f -o default -X '!*.texi*' makeinfo texi2dvi texi2html texi2pdf
    complete -f -o default -X '!*.tex' tex latex slitex
    complete -f -o default -X '!*.lyx' lyx
    complete -f -o default -X '!*.+(htm*|HTM*)' lynx html2ps
    # Multimedia
    complete -f -o default -X '!*.+(jp*g|gif|xpm|png|bmp)' xv gimp
    complete -f -o default -X '!*.+(mp3|MP3)' mpg123 mpg321
    complete -f -o default -X '!*.+(ogg|OGG)' ogg123


    complete -f -o default -X '!*.pl'  perl perl5
    # This is a 'universal' completion function - it works when commands have
    # a so-called 'long options' mode , ie: 'ls --all' instead of 'ls -a'
    _get_longopts ()
    {
        $1 --help | sed  -e '/--/!d' -e 's/.*--\([^[:space:].,]*\).*/--\1/'| \
    grep ^"$2" |sort -u ;
    }
    _longopts_func ()
    {
        case "${2:-*}" in
            -*)     ;;
            *)      return ;;
        esac
        case "$1" in
            \~*)    eval cmd="$1" ;;
            *)      cmd="$1" ;;
        esac
        COMPREPLY=( $(_get_longopts ${1} ${2} ) )
    }
    complete  -o default -F _longopts_func configure bash
    complete  -o default -F _longopts_func wget id info a2ps ls recode

    _make_targets ()
    {
        local mdef makef gcmd cur prev i
        COMPREPLY=()
        cur=${COMP_WORDS[COMP_CWORD]}
        prev=${COMP_WORDS[COMP_CWORD-1]}
        # if prev argument is -f, return possible filename completions.
        # we could be a little smarter here and return matches against
        # `makefile Makefile *.mk', whatever exists
        case "$prev" in
            -*f)    COMPREPLY=( $(compgen -f $cur ) ); return 0;;
        esac
        # if we want an option, return the possible posix options
        case "$cur" in
            -)      COMPREPLY=(-e -f -i -k -n -p -q -r -S -s -t); return 0;;
        esac
        # make reads `makefile' before `Makefile'
        if [ -f makefile ]; then
            mdef=makefile
        elif [ -f Makefile ]; then
            mdef=Makefile
        else
            mdef=*.mk               # local convention
        fi
        # before we scan for targets, see if a makefile name was specified
        # with -f
        for (( i=0; i < ${#COMP_WORDS[@]}; i++ )); do
            if [[ ${COMP_WORDS[i]} == -*f ]]; then
                eval makef=${COMP_WORDS[i+1]}       # eval for tilde expansion
                break
            fi
        done
            [ -z "$makef" ] && makef=$mdef
        # if we have a partial word to complete, restrict completions to
        # matches of that word
        if [ -n "$2" ]; then gcmd='grep "^$2"' ; else gcmd=cat ; fi
        # if we don't want to use *.mk, we can take out the cat and use
        # test -f $makef and input redirection
        COMPREPLY=( $(cat $makef 2>/dev/null | ${AWK} 'BEGIN {FS=":"} /^[^.#   ][^=]*:/ {print $1}' | tr -s ' ' '\012' | sort -u | eval $gcmd ) )
    }
    complete -F _make_targets -X '+($*|*.[cho])' make gmake pmake

    # cvs(1) completion
    _cvs ()
    {
        local cur prev
        COMPREPLY=()
        cur=${COMP_WORDS[COMP_CWORD]}
        prev=${COMP_WORDS[COMP_CWORD-1]}
        if [ $COMP_CWORD -eq 1 ] || [ "${prev:0:1}" = "-" ]; then
            COMPREPLY=( $( compgen -W 'add admin checkout commit diff \
            export history import log rdiff release remove rtag status \
            tag update' $cur ))
        else
            COMPREPLY=( $( compgen -f $cur ))
        fi
        return 0
    }
    complete -F _cvs cvs
    _killall ()
    {
        local cur prev
        COMPREPLY=()
        cur=${COMP_WORDS[COMP_CWORD]}
        # get a list of processes (the first sed evaluation
        # takes care of swapped out processes, the second
        # takes care of getting the basename of the process)
        COMPREPLY=( $( /usr/bin/ps -u $USER -o comm  | \
            sed -e '1,1d' -e 's#[]\[]##g' -e 's#^.*/##'| \
            ${AWK} '{if ($0 ~ /^'$cur'/) print $0}' ))
        return 0
    }
    complete -F _killall killall killps

    # A meta-command completion function for commands like sudo(8), which need to
    # first complete on a command, then complete according to that command's own
    # completion definition - currently not quite foolproof (e.g. mount and umount
    # don't work properly), but still quite useful - By Ian McDonald, modified by me.
    _my_command()
    {
        local cur func cline cspec
        COMPREPLY=()
        cur=${COMP_WORDS[COMP_CWORD]}
        if [ $COMP_CWORD = 1 ]; then
            COMPREPLY=( $( compgen -c $cur ) )
        elif complete -p ${COMP_WORDS[1]} &>/dev/null; then
            cspec=$( complete -p ${COMP_WORDS[1]} )
            if [ "${cspec%%-F *}" != "${cspec}" ]; then
                # complete -F
                #
                # COMP_CWORD and COMP_WORDS() are not read-only,
                # so we can set them before handing off to regular
                # completion routine

                # set current token number to 1 less than now
                COMP_CWORD=$(( $COMP_CWORD - 1 ))
                # get function name
                func=${cspec#*-F }
                func=${func%% *}
                # get current command line minus initial command
                cline="${COMP_LINE#$1 }"
                # split current command line tokens into array
                    COMP_WORDS=( $cline )
                $func $cline
            elif [ "${cspec#*-[abcdefgjkvu]}" != "" ]; then
                # complete -[abcdefgjkvu]
                #func=$( echo $cspec | sed -e 's/^.*\(-[abcdefgjkvu]\).*$/\1/' )
                func=$( echo $cspec | sed -e 's/^complete//' -e 's/[^ ]*$//' )
                COMPREPLY=( $( eval compgen $func $cur ) )
            elif [ "${cspec#*-A}" != "$cspec" ]; then
                # complete -A
                func=${cspec#*-A }
            func=${func%% *}
            COMPREPLY=( $( compgen -A $func $cur ) )
            fi
        else
            COMPREPLY=( $( compgen -f $cur ) )
        fi
    }


    complete -o default -F _my_command nohup exec eval trace truss strace sotruss gdb
    complete -o default -F _my_command command type which man nice

    # Given a PATH like string and a separator, remove duplicate entries
    removeDups() # string sep
    {
      if [ "${osname}" = "windows" ] ; then
        printf "%s\n" "$1" | \
          sed -e 's@\\@/@g' | \
          ${AWK} -F"$2" \
           '{ \
              a[toupper($1)]; \
              printf "%s",$1; \
              for(i=2;i<=NF;i++){ \
                if(!(toupper($i) in a)){ \
                  a[toupper($i)]; \
                  printf "%s%s",FS,$i; \
                } \
              }; \
              printf "\n"; \
            }'
      else
        printf "%s\n" "$1" | \
          ${AWK} -F"$2" \
           '{ \
              a[$1]; \
              printf "%s",$1; \
              for(i=2;i<=NF;i++){ \
                if(!($i in a)){ \
                  a[$i]; \
                  printf "%s%s",FS,$i; \
                } \
              }; \
              printf "\n"; \
            }'
      fi
    }
    # Need particular AWK
    sep=":"
    # Get new path setting
    newpath=`removeDups "${PATH}" "${sep}"`
    newmanpath=`removeDups "${MANPATH}" "${sep}"`
    # Redefine your PATH setting
    if [ "${PATH}" != "${newpath}" ] ; then
    #  echo "# Resetting PATH to remove duplicates"
      PATH_ORIGINAL="${PATH}"
      MANPATH_ORIGINAL="${MANPATH}"
      export PATH_ORIGINAL
      export MANPATH_ORIGINAL
      PATH="${newpath}"
    MANPATH="${newmanpath}"
      export MANPATH
      export PATH
    fi
    #echo end dot bashrc