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

-
Current Location
-

js
  Downloads
    Scripts
      Korn
        K93_Unix
-
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



#!/usr/bin/ksh93
################################################################
#### Program: tail_k93
#### 
#### Description: Emulation of the Unix "tail" command
#### 
#### Author: Dana French (dfrench@mtxia.com)
#### 
#### Date: 07/22/2004
#### 
################################################################
function tail_k93 {
  typeset TRUE="0"
  typeset FALSE="1"
  typeset VERYFALSE="2"
  typeset CAT="${FALSE}"
  typeset LINES="${TRUE}"
  typeset BYTES="${FALSE}"
  typeset OLDPREV=""
  typeset FNAME=""
  typeset TAILCNT=""

  typeset STDIN="${1:+${FALSE}}"
  STDIN="${STDIN:-${TRUE}}"

  while getopts ":0123456789c#n#vV" OPTION
  do
    case "${OPTION}" in
        'c') BYTES="${TRUE}"
             TAILCNT="${OPTARG}"
             LINES="${FALSE}";;
        'n') LINES="${TRUE}"
             TAILCNT="${OPTARG}"
             BYTES="${FALSE}";;
        'v') VERBOSE="${TRUE}";;
        'V') VERYVERB="${TRUE}";;
        '?') print "Syntax: tail [-Count|-c bytes|-n lines] [FILE]..." && exit 1 ;;
    esac

    let "${OPTION} + 0" > /dev/null 2>&1 &&
        (( CAT == FALSE )) &&
        CAT="${TRUE}"

    ! let "${OPTION} + 0" > /dev/null 2>&1 &&
        (( CAT == TRUE )) &&
        CAT="${VERYFALSE}"

    let "${OPTION} + 0" > /dev/null 2>&1 &&
        (( OPTION == 0 )) &&
        (( CAT == VERYFALSE )) &&
        CAT="${TRUE}"

    (( CAT == TRUE )) && TAILCNT="${TAILCNT}${OPTION}"
  done
 
  shift $(( ${OPTIND} - 1 ))

  typeset STDIN="${1:+${FALSE}}"
  STDIN="${STDIN:-${TRUE}}"

  if (( STDIN == TRUE ))
  then
          getTailLine_k93 "${TAILCNT}" "${BYTES}" "${LINES}"
  else
    for FNAME in "${@}"
    do
      if [[ -f "${FNAME}" ]]
      then      
        exec 0<"${FNAME}"
          getTailLine_k93 "${TAILCNT}" "${BYTES}" "${LINES}"
        exec 0<&-
      else
        print -u 2 "ERROR: \"${FNAME}\" does not exist or is not a regular file."
      fi
    done
  fi
  return 0
}
################################################################
function getTailLine_k93 {
  typeset TAILCNT="${1}"
  typeset BYTES="${2}"
  typeset LINES="${3}"

  [[ "_${TAILCNT}" = "_" ]] && TAILCNT="10"

    if (( BYTES == TRUE ))
    then

      CCNT="0"
      while IFS="" read -r -- LINE
      do
        (( CCNT = CCNT + ${#LINE} ))
        if (( CCNT >= TAILCNT ))
        then
          TAILLINE="${TAILLINE}"$'\n'"${LINE}"
          TCNT="${#TAILLINE}"
          (( DIFF = TCNT - TAILCNT ))
          TAILLINE="${TAILLINE:DIFF-1}"
        fi
        (( CCNT = CCNT + ${#TAILLINE} ))
      done

      (( DIFF = ${#TAILLINE} - TAILCNT ))
      print -- "${TAILLINE:DIFF}"
    fi

    if (( LINES == TRUE ))
    then

      LCNT="0"
      while IFS="" read -r -- LINE
      do
        if (( LCNT >= TAILCNT ))
        then
          for (( i=1; i<TAILCNT; ++i ))
          do
            ARRY[i-1]="${ARRY[i]}"
          done
          ARRY[TAILCNT-1]="${LINE}"
        else
          ARRY[LCNT]="${LINE}"
        fi
        (( LCNT++ ))
      done
      for LINE in "${ARRY[@]}"
      do
          print -r -- "${LINE}"
      done
    fi

  return 0
}
################################################################

tail_k93 "${@}"

-
tail_k93
-
 


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