Home About BC DR HA Support Training Download
You are here: Home/ Downloads/ Scripts/ Korn/ Functions/ Please Login or Register

-
Current Location
-

js
  Downloads
    Scripts
      Korn
        Functions
-
AIX Admin Methodology
Global Consolidation Project
All AIX admins should join
www.aixexpert.com


Join our LinkedIn Group
AIX Advanced Technical Experts
Contract Opportunities

www.LinkedIn.com

-
digg Digg this page
del.icio.us Post to del.icio.us
Slashdot Slashdot it!


LPAR Leasing
Lease an AIX / i5 LPAR
Reduce your costs

www.mtxia.com

Server Leasing
Lease a Server off-site
Reduce your costs

www.mtxia.com

Data Center Automation
Business Continuity and DR
Virtualization/Consolidation

www.mtxia.com

HMC Service
Hardware Management Console
Manage Remote AIX / i5 LPARs

www.siteox.com

Business Web Site Hosting
$3.99 / month includes Tools,
Shopping Cart, Site Builder

www.siteox.com

Disaster Recovery
Small Business Oriented
Off-Site Facilities

www.mtxia.com

IBM pSeries / iSeries
Reduce your Costs
Off-Site Server Hosting

www.mtxia.com

mkuid

Korn Shell mkuid: Generate Enterprise Wide unique UID/GID number/values for usernames and group names




################################################################
#### 
#### This Korn Shell 93 function generates a uniq UID number/value
#### for a username, that username must consist of 3 letters 
#### followed by 4 digits, or 4 letters followed by 3 digits.  The 
#### username is assumed to be the first argument to the function. 
#### The username must also be exactly 7 characters long.
#### 
#### This function is dependent upon the external 
#### function "mkascii".
#### 
################################################################
function mkuid
{
  typeset -l MKUID_LET
  typeset MKUID_NUMLET=0
  
  MKUID_NUMLET="${1//([!a-zA-Z])/}"
  MKUID_NUMLET="${#MKUID_NUMLET}"

  if (( ${#1} != 7 ))
  then
      print -u 2 "ERROR: Number of characters in username ${1} is not equal to 7\n"
      return -1
  fi
  
  if (( MKUID_NUMLET != 3 )) && (( MKUID_NUMLET != 4 ))
  then
      print -u 2 "ERROR: Number of letters in username ${1} is not equal to 3 or 4\n"
      return -1
  fi
  
  (( MKUID_TYPE = 10 ** ( 7 - MKUID_NUMLET ) ))
  typeset MKUID_LOWLIM=1000000
  (( MKUID_LOWUID = ( 26 ** ( MKUID_NUMLET - 1 ) * MKUID_LOWLIM / 100 ) + MKUID_LOWLIM ))
  (( MKUID_NUMLET == 3 )) && (( MKUID_LOWUID = MKUID_LOWLIM ))
  
  typeset MKUID_BASE=26
  typeset MKUID_NVALUE=""
  typeset MKUID_LVALUE=0
  typeset MKUID_ECNT=0
  typeset MKUID_SUBTOT=0
  typeset MKUID_TOT=0
  typeset MKUID_MULT=0
  
  typeset -A MKUID_LETTERS
  mkascii MKUID_LETTERS
  
  # print " ${MKUID_LETTERS[@]}"
  
  eval EACHLET="( ${1//(?)/ \1} )"
  for MKUID_LET in "${EACHLET[@]}"
  do
  
    if [[ "_${MKUID_LET}" = _[a-z] ]]
    then
      MKUID_LVALUE="$(( ${MKUID_LETTERS[${MKUID_LET}]} - 97 ))"
    else
      MKUID_LVALUE="0"
      MKUID_NVALUE="${MKUID_NVALUE}${MKUID_LET}"
    fi
  
    (( MKUID_MULT = MKUID_BASE ** MKUID_ECNT ))
    (( MKUID_SUBTOT = MKUID_SUBTOT + MKUID_LVALUE * MKUID_MULT ))
    (( MKUID_ECNT = MKUID_ECNT + 1 ))
  done
  
  (( MKUID_TOT = ( ( MKUID_SUBTOT * MKUID_TYPE ) + MKUID_NVALUE ) + MKUID_LOWUID ))
  
  print ${MKUID_TOT}
  return 0
}

-
Unique UID Number
-
 


LPAR Leasing
Lease an AIX / i5 LPAR
Reduce your costs

www.mtxia.com

Server Leasing
Lease a Server off-site
Reduce your costs

www.mtxia.com

Data Center Automation
Business Continuity and DR
Virtualization/Consolidation

www.mtxia.com

HMC Service
Hardware Management Console
Manage Remote AIX / i5 LPARs

www.siteox.com

Business Web Site Hosting
$3.99 / month includes Tools,
Shopping Cart, Site Builder

www.siteox.com

FREE Domain Registration
included with Web Site Hosting
Tools, Social Networking, Blog

www.siteox.com

Disaster Recovery
Small Business Oriented
Off-Site Facilities

www.mtxia.com

IBM pSeries / iSeries
Reduce your Costs
Off-Site Server Hosting

www.mtxia.com