scripts1.doc - VU scripts for Conversion & General use - Contents

scripts1.doc - Contents by Part#

Part_0
  • Introduction & Overview of Vancouver Utility scripts
  • scripts1.doc (this book) vs CNVaids.htm vs ADMjobs.htm
  • where scripts are stored & how they are accessed (PATH)
  • do not modify VU scripts in /home/uvadm/sf/...
  • setup appsadm account & copy/modify scripts in /home/appsadm/sf/...
  • search PATH priority is $HOME/sf/, /home/appsadm/sf/, /home/uvadm/sf/
Part_1
  • file 'rename' script
  • over 20 rename scripts, useful for conversions & general purpose
  • rename all scripts in a directory matching specified criteria
  • add/remove/change suffixes, prefixes, or patterns within filenames
  • translate to UPPER, or to lower, convert '$' to '_', blank to '_', etc
  • save a lot of manual keyboard drudgery
Part_2
  • aliases, can also save a lot of keystrokes
  • alias l='ls -l' saves keystrokes for this often repeated command
  • short aliases to change to programmer common libraries & data
    (cdl='cd $RUNLIBS' & cdd='cd $RUNDATA')
Part_3
  • listing file & directory names (not data contents)
  • scripts to list directories (lla, lld, llm, llr, llt, lls, llu)
    lla All, lld Dirs only, llm pipe to More, llr Recursive, llt by Time,
    lls by Size, llu Unsorted.
  • lslp list files & print immediately
  • spreadA list filenames 4-up across the page
Part_4
  • scripts to process ALL files in a directory
  • alldiff, allcmp, alldos2unix, allunix2dos, allrm, rmzf
  • rmold1, rmold2, rmold3, vis (edit multi files in dir in size order)
Part_5
  • scripts to count files in directories & sub-directories
    (countf, countfd, countfl, countflp, statdir1)
    statdir1 - shows total files & total KB in each subdir
Part_6
  • copying & sorting all files from 1 directory to a 2nd directory
  • copycpio1, copycpio2, copydate, cpnew1, cpnew2
  • sortcpio, sortdirs, sortall
Part_7
  • system/application administration scripts
  • some require 'root' permissions
  • killuser1, killuser2, chmod1, chmod2, chmod3, ftrigger51, ftrigger52
  • we also list 'crontab_root' used to schedule 'killuser2' at 3 AM
  • see several other 'unix administration' type scripts in ADMjobs.htm
  • scripts for backup/restore, crontabs to run nightly scripts, etc

Goto:   Begin this document End this document UVSI Home-Page

Part_0 Vancouver Utility scripts for Conversion & General use

scripts calling unix/linux vs Vancouver Utilities

This scripts1.doc is intended to document 'general purpose' scripts that could be useful to any unix/linux user. Most of these scripts call standard unix/linux utilities (ls,mv,cp,cpio,diff,cmp,kill,etc) vs Vancouver Utilities (uvcopy,uvlist,uvsort,uvcp,uvhd,etc).

scripts1.doc lists about 40 of the most useful of the more than 500 scripts distributed in the Vancouver Utilities package. You can save this document, cut out the scripts that interest you, & transfer them to your unix/linux.

If you are a Vancouver Utilities customer, you have access to all scripts in the scripts directory as shown on the next page.

scripts1.doc vs CNVaids.doc

If you are more interested in scripts that could be useful during mainframe conversions (of JCL, COBOL,& EBCDIC DATA files), please see CNVaids.htm. Some of the scripts in CNVaids.htm call only unix/linux commands, but many of them do call Vancouver Utilities.

scripts1.doc vs ADMjobs.doc

Also see ADMjobs.htm for administrative type scripts such as 'backups' & scripts run by 'cron'. Again the intention of this scripts1.doc is to present the more general purpose scripts that could be useful to any unix/linux user.

Pre-Requisites to running test/demo scripts

  1. Your site administrator has installed the Vancouver Utilities. Please see the directory diagrams on the next page, showing only the subdirs relevant to running these test/demo scripts.

  2. Your site administrator has setup a login/homedir for you AND has setup the profiles to give you access to the Vancouver Utility programs, scripts, and uvcopy parameter files.

  3. If you are the site administrator, please see ADMjobs.htm#Part_1 for listings of the supplied profiles & how best to set them up.

Goto:   Begin this document End this document UVSI Home-Page

0A2. Vancouver Utility scripts for Conversion & General use

VU scripts - where stored, how accessed (PATH)

 /home/uvadm        <-- Vancouver Utilities homedir
 :-----bin               - binaries (uvcopy,uvsort,etc)
 :-----doc               - documentation
 :     :                 - other subdirs omitted
 :     :
 :-----sf              <-- Script Files (sub-directoried for uvadm only)
 :     :-----adm         - administrative scripts
 :     :-----demo        - demo scripts
 :     :-----IBM         - IBM mainframe conversion scripts
 :     :-----util        - utility scripts
 :     :
 /home/appsadm    <-- appsadm homedir
 :-----bin              - binaries for site developed/modified programs
 :-----env              - profiles modified for your site
 :-----logs             - backup logs (run by cron)
 :     :                - other subdirs omitted
 :     :
 :-----sf             <-- shell scripts developed/modified by appsadm
 :     :
 /home/userxx     <-- user homedirs
 :     :
 :-----sf             <-- shell scripts developed/modified by appsadm
 :     :

relevant lines from common_profile

 export UV=/home/uvadm                # <-- UV homedir symbol used below
 export APPSADM=/home/appsadm         # <-- site applications administrator
 export PATH=$PATH:$HOME/bin:$HOME/sf:$APPSADM/bin:$APPSADM/sf:$RUNLIBS/sf
 export PATH=$PATH:$UV/bin:$UV/sf/adm:$UV/sf/demo:$UV/sf/util:$UV/sf/IBM

The uvadm scripts directory is sub-directoried (sf/adm,sf/demo,sf/IBM,sf/util).

Note that the recommended profile (see ADMjobs.htm#1C3) searches the PATH of appsadm before uvadm, so any scripts that appsadm modifies will be found before any of the original scripts/jobs. Also note that the PATH searches $HOME/sf before /home/appsadm, so users could copy/modify a script in their homedir & it will be found before either appsadm/sf or uvadm/sf/...

Goto:   Begin this document End this document UVSI Home-Page

0A3. Vancouver Utility scripts for Conversion & General use

uvadm, appsadm,& user homedirs

We recommend you setup a login/userid 'appsadm' to serve as the applications administrator for the unix/linux site. The appsadm home directory would hold various scripts, crontabs, log files, etc used in application administration.

One important purpose of appsadm is to hold the modified versions of any Vancouver Utility profiles, scripts & uvcopy jobs that you need to customize at your site.

Scripts that are useful to all programmers & operators should be stored in /home/appsadm/sf/... Scripts that are useful only to individual programmers should be stored in their homedirs /home/userxx/sf/...

This protects you from losing your customized versions when you install a future new version of Vancouver Utilities, which would overwrite your modified versions if stored in /home/uvadm/...

setup to run uvcopy test/demo jobs


 #1. Login to your homedir

 #2a. mkdir sf        <-- make subdir for your own scripts
      ========          - or to copy/modify scripts from /home/uvadm/sf/...

 #2b. mkdir dat1 tf   <-- make subdirs for the test/demo files
      =============

 #2c. mkdir tmp       <-- make subdir for test/demo outputs
      =========

 #3a. cp /home/uvadm/dat1/* dat1  <-- copy test/demo files to your homedir
      ==========================

 #3b. cp /home/uvadm/tf/* tf       <-- copy test/demo files to your homedir
      ======================

Goto:   Begin this document End this document UVSI Home-Page

Part_1 - Vancouver Utility scripts for Conversion & General use - Contents

file 'rename' scripts - Contents

Note
  • these scripts rename ALL files in a specified directory
    meeting a specified criteria
 1A1. Example using rename scripts to save hours of drudgery
      - renaming hundreds of mainframe files FTP'd to unix/linux

1B1. rename-A - remove pattern occurring anywhere in filename 1C1. renameAA - replace pattern with alternate anywhere

 1D1. renameB  - change any embedded blanks to underscores

1E1. renameDU - change any '$' dollar signs to '_' underscores

 1F1. renameG  - change GDG suffixes G####V00 to _0001
 1G1. renameL  - translate filenames to lower case

1H1. renameLX - translate extensions to lower case

 1I1. renameP  - replace existing prefix with alternate
 1J1. rename-P - remove a specified prefix
 1K1. rename+P - add a specified prefix

1L1. renameParens - rename using name from within embedded (parens)

 1M1. renameU  - translate filenames to UPPER case
 1N1. renameU1 - translate 1st char of filenames to UPPER case
 1O1. renameX  - change specified extension to a specified alternate
 1P1. rename-X - remove a specified extension
 1Q1. rename+X - add a specified extension

1R1. renameQQ - remove Quotes

'rename' scripts - Why you need them

  1. These scripts rename all files in a specified directory, meeting a specified condition (optionally).

  2. These scripts save a lot of manual keyboard entries when hundreds of files must be renamed - boring, error-prone work.

  3. Renaming hundreds of files is often required during mainframe conversions.

Goto:   Begin this document End this document UVSI Home-Page

1A1. Vancouver Utility scripts for Conversion & General use

example - renaming Mainframe Data Files

Here is a great example of the extreme usefulness of these 'rename' scripts.

When mainframe files are transferred to unix/linux, we like to translate the filenames to lower case & remove any extraneous extensions, as shown below:

/p4/cnvdata :---dat0 <-- directory to receive files FTP'd from Mainframe : : : :---E2121653.MTAXE.PISCINES.CLUS.VSEPRD <-- filenames from MAINFRAME : :---E2121656.ITAXE.FACTURAT.CLUS.VSEPRD : :---E2122683.ITAXE.DEGREVEM.CLUS.VSEPRD : :---E2123003.ITAXE.TRANSDAM : :---TU.F01.E212-NO.TRPERM

 :---dat1   <-- directory to rename files for unix/linux
 :   :
 :   :---e2121653.mtaxe.piscines          <-- filenames desired on Unix/Linux
 :   :---e2121656.itaxe.facturat
 :   :---e2122683.itaxe.degrevem
 :   :---e2123003.itaxe.transdam
 :   :---tu.f01.e212-no.trperm

Operating Instructions

Assuming files have already been FTP'd to /p4/cnvdata/dat0/... as shown above.


 #1a. Login userxx --> /home/userxx

 #1b. cd $CNVDATA --> /p4/cnvdata

 #2. cp dat0/* dat1    <-- copy files to dat1/... for renaming
     ==============

 #3. renameL dat1      <-- translate all filenames in dat1/... to lower case
     ============

 #4. rename-X dat1 .CLUS.VSEPRD  <-- remove unwanted extensions
     ==========================

See the 'renameL' script listed on page '1G1' & 'rename-X' on page '1P1'.

Without these scripts, it would be a very long, boring, error-prone job to rename the scripts as desired, using commands such as:

      cd dat1
      mv E2121653.MTAXE.PISCINES.CLUS.VSEPRD e2121653.mtaxe.piscines
      mv E2121656.ITAXE.FACTURAT.CLUS.VSEPRD e2121656.itaxe.facturat

Goto:   Begin this document End this document UVSI Home-Page

1B1. scripts1.doc - Vancouver Utility scripts for Conversion & General use

rename-A - remove pattern occurring anywhere in filename

 #!/bin/ksh
 # rename-A - Korn shell script from UVSI stored in: /home/uvadm/sf/util/
 # rename-A - rename an entire directory of filenames
 #          - removing a specified pattern that can occur Anywhere in filename
 #
 echo "rename files in subdir - removing a pattern that can occur Anywhere"
 if [ -d "$1" -a -n "$2" ]; then :
    else echo "usage: rename-A directory pattern"
         echo "       =========================="
         exit 1; fi
 #
 reply="n"
 until [ "$reply" = "y" ]
 do echo "do you have backup ? y/n"
    read reply
 done
 x=0; y=0
 for dfn in $1/*
 do fn=${dfn##*/}           # remove any preceding directories
    fn1=${fn%${2}*}         # remove smallest matching suffix
    fn2=${fn#*${2}}         # remove smallest matching prefix
    fn3=${fn1}${fn2}        # concatenate the left & right remainders
    let x=x+1
    if [[ $fn3 != $fn ]]; then
       mv -i $1/$fn $1/$fn3
       #==================
       let y=y+1
       echo "file# $x $1/$fn - renamed to: $1/$fn3"
    fi
 done
 echo "total $x files, $y renamed (removing $2 pattern)"
 exit 0

Goto:   Begin this document End this document UVSI Home-Page

1C1. scripts1.doc - VU scripts for Conversion & General use

renameAA - replace pattern with alternate anywhere

 #!/bin/ksh
 # renameAA - Korn shell script from UVSI stored in: /home/uvadm/sf/util/
 # renameAA - rename an entire directory of filenames
 #          - replacing Any pattern Anywhere in filename with an Alternative
 #
 echo "rename files in subdir - replacing a pattern that can occur Anywhere"
 if [[ (-d "$1") && (-n "$2") && (-n "$3") ]]; then :
    else echo "usage: renameAA directory pattern altpattern"
         echo "       ====================================="
         exit 1; fi
 #
 reply="n"
 until [ "$reply" = "y" ]
 do echo "do you have backup ? y/n"
    read reply
 done
 x=0; y=0
 for dfn in $1/*
 do fn=${dfn##*/}           # remove any preceding directories
    if [[ $fn != *${2}* ]] then continue; fi
    fn1=${fn%${2}*}         # remove smallest matching suffix
    fn2=${fn#*${2}}         # remove smallest matching prefix
    fn3=${fn1}${3}${fn2}    # concatenate left-part, altpattern,& right-part
    let x=x+1
    if [[ $fn3 != $fn ]]; then
       mv -i $1/$fn $1/$fn3
       #===================
       let y=y+1
       echo "file# $x $1/$fn - renamed to: $1/$fn3"
    fi
 done
 echo "total $x files, $y renamed (replacing $2 with $3)"
 exit 0

Goto:   Begin this document End this document UVSI Home-Page

1D1. scripts1.doc - VU scripts for Conversion & General use

renameB - change any embedded blanks to underscores

 #!/bin/ksh
 # renameB - Korn shell script from UVSI stored in: /home/uvadm/sf/util/
 # renameB - rename all files in a directory, changing any blanks to underscores
 #
 echo "rename all files in a directory, changing any blanks to underscores"
 if [ -d "$1" ]; then :
    else echo "usage: renameB directory  <-- arg1 must be a directory"
         echo "       ================="
         exit 1; fi
 #
 reply="n"
 until [ "$reply" = "y" ]
 do echo "enter 'y' to rename files in $1 changing any blanks to underscores"
    read reply
 done
 #
 x=0; y=0
 for i in $1/*
 do let x=x+1
    f=${i##*/}
 ## typeset -l g=$f
    g=$(echo $f | tr " " "_")
    if [[ $g != $f ]]; then
       mv -i "$1/$f" $1/$g
       #==================
       let y=y+1
       echo "file# $y (of $x) $1/$f - renamed to: $1/$g"
    fi
 done
 echo "total $y files in ${1}, $x renamed changing blanks to underscores"
 exit 0

Goto:   Begin this document End this document UVSI Home-Page

1E1. scripts1.doc - VU scripts for Conversion & General use

renameDU - change any '$' dollar signs to '_' underscores

 #!/bin/ksh
 # renameDU - Korn shell script from UVSI stored in: /home/uvadm/sf/util/
 # renameDU - rename changing dollar signs to underscores
 #
 echo "rename changing dollar signs to underscores."
 if [ -d "$1" ]; then :
    else echo "usage: renameDU directory  <-- arg1 must be a directory"
         echo "       ================="
         exit 1; fi
 #
 reply="n"
 until [ "$reply" = "y" ]
 do echo "rename changing dollar signs to underscores? y/n"
    read reply
 done
 #
 x=0; y=0
 for i in $1/*
 do let y=y+1
    f=${i##*/}
    g=$(echo $f | tr '$' '_')
    if [[ $g != $f ]]; then
       mv -i $1/$f $1/$g
       #================
       let x=x+1
       echo "file# $x (of $y) $1/$f  - renamed to:  $1/$g"
    fi
 done
 echo "total $y files in ${1}, $x renamed changing dollar signs to underscores."
 exit 0

Goto:   Begin this document End this document UVSI Home-Page

1F1. scripts1.doc - VU scripts for Conversion & General use

renameG - change GDG suffixes G####V00 to _0001

 #!/bin/ksh
 # renameG - Korn shell script from UVSI stored in: /home/uvadm/sf/util/
 # renameG - change file suffix G####VXX to _0001 for all files in a directory
 #         - for mainframe GDG file conversions to unix/linux/windows
 #         - for exportgen functions called by JCL/scripts converted by VU
 #         - see DATAcnv2.doc or www.uvsoftware.ca/datacnv2.htm
 #
 echo "change all suffixes from G####VXX to _0001"
 if [[ ! -d "$1" ]]; then
    echo "usage:   renameG directory (arg1 must be a directory)"
    echo "         ================="
    echo "example: renameG mstr"
    echo "         ============"
    exit 1;
 fi
 d=$1; x=0; y=0;
 for df in $d/*
   do let x=x+1
      if [[ $df == *G[0-9][0-9][0-9][0-9]V?? ]]; then
         f1=$(basename $df)
         f2=${f1%G[0-9][0-9][0-9][0-9]V??}
         f3=${f2}_0001
         mv -f $d/$f1 $d/$f3
         #==================
         echo "file# $x - $d/$f1 renamed to: $d/$f3"
         let y=y+1
      fi
   done
 echo "EOD - $y files renamed of $x total in $d"
 exit 0

Goto:   Begin this document End this document UVSI Home-Page

1G1. scripts1.doc - VU scripts for Conversion & General use

renameL - translate all filenames to lower case

 #!/bin/ksh
 # renameL - Korn shell script from UVSI stored in: /home/uvadm/sf/util/
 # renameL - rename an entire directory of filenames to lower case
 #
 echo "rename all filenames in subdir to lower case"
 if [ -d "$1" ]; then :
    else echo "usage: renameL directory  <-- arg1 must be a directory"
         echo "       ================="
         exit 1; fi
 #
 reply="n"
 until [ "$reply" = "y" ]
 do echo "will rename all files in $1 to lower case OK ? y/n"
    read reply
 done
 #
 x=0; y=0
 for i in $1/*
 do let x=x+1
    f=${i##*/}
    typeset -l g=$f
    if [[ $g != $f ]]; then
       mv -i $1/$f $1/$g
       #================
       let y=y+1
       echo "file# $y (of $x) $1/$f - renamed to: $1/$g"
    fi
 done
 echo "total $y files in ${1}, $x renamed to lower case"
 exit 0

Goto:   Begin this document End this document UVSI Home-Page

1H1. scripts1.doc - VU scripts for Conversion & General use

renameLX - translate extensions to lower case

 #!/bin/ksh
 # renameLX - Korn shell script from UVSI stored in: /home/uvadm/sf/util/
 # renameLX - rename all files in directory to lower case extensions
 #          - example: JCLXXX.JCL to JCLXXX.jcl
 #
 echo "rename all filenames in subdir to lower case extensions"
 d="$1"
 if [ -d "$d" ]; then :
    else echo "usage: renameLX directory  <-- arg1 must be a directory"
         echo "       =================="
         exit 1; fi
 #
 reply="n"
 until [ "$reply" = "y" ]
 do echo "will rename all files in $d to lower case extensions OK ? y/n"
    read reply
 done
 #
 m=0; n=0
 for dFX in $d/*
 do let m=m+1
    FX=${dFX##*/}             # remove directory/ = FILE.EXT
    F=${FX%.*}                # remove .EXT = FILE
    X=${FX##*.}               # remove FILE. = EXT
    typeset -l x=$X           # translate EXT to lower case ext
    Fx=$F.$x                  # concat orig FILE + '.' + ext (lowercased)
    if [[ $Fx != $FX ]]; then # avoid rename if already lowercase ext
       mv -i $d/$FX $d/$Fx    # rename extension to lowercase
       #==================
       let n=n+1
       echo "file# $m $d/$FX - renamed to: $d/$Fx"
    fi
 done
 echo "$n extensions lowercased of $m total files in $d"
 exit 0
 #

Goto:   Begin this document End this document UVSI Home-Page

1I1. scripts1.doc - VU scripts for Conversion & General use

renameP - replace existing prefix with alternate

 #!/bin/ksh
 # renameP - Korn shell script from UVSI stored in: /home/uvadm/sf/util/
 # renameP - rename an entire directory of filenames
 #         - replacing an existing prefix with a new prefix
 #         - may use pattern characters in prefix
 #
 echo "rename all filenames in subdir - replace prefix with alternate"
 if [[ -d "$1" && -n "$2" && -n "$3" ]]; then :
    else echo "usage: renameP directory oldprefix newprefix"
         echo "       ====================================="
         exit 1; fi
 reply="n"
 until [[ "$reply" = "y" ]]
 do echo "do you have backup ? y/n"
    read reply
 done
 x=0; y=0
 for i in $1/*
 do f=${i##*/}                  # remove any preceding directories
    g=${f#$2}                   # remove smallest matching old prefix
    h=${3}${g}                  # insert new prefix
    let x=x+1
    if [[ ($f == *${2}*) && ($h != $f) ]]; then
       mv -i $1/$f $1/$h
       #================
       let y=y+1
       echo "file# $x - $1/$f  - renamed to:  $1/$h"
    fi
 done
 echo "total $x files, $y renamed (replacing prefix $2 with $3)"
 exit 0

Goto:   Begin this document End this document UVSI Home-Page

1J1. scripts1.doc - VU scripts for Conversion & General use

rename-P - remove a specified prefix

 #!/bin/ksh
 # rename-P - Korn shell script from UVSI stored in: /home/uvadm/sf/util/
 # rename-P - rename an entire directory of filenames
 #          - removing a specified prefix
 #          - may use pattern characters in prefix
 #
 echo "rename all filenames in subdir - removing a specified prefix"
 if [ -d "$1" -a -n "$2" ]; then :
    else echo "usage: rename-P directory prefix"
         echo "       ========================="
         exit 1; fi
 reply="n"
 until [ "$reply" = "y" ]
 do echo "do you have backup ? y/n"
    read reply
 done
 x=0; y=0
 for i in $1/*
 do f=${i##*/}                  # remove any preceding directories
    g=${f#$2}                   # remove smallest matching prefix
    let x=x+1
    if [[ $g != $f ]]; then
       mv -i $1/$f $1/$g
       #================
       let y=y+1
       echo "file# $x - $1/$f  - renamed to:  $1/$g"
    fi
 done
 echo "total $x files, $y renamed (removing $2 prefix)"
 exit 0

Goto:   Begin this document End this document UVSI Home-Page

1K1. scripts1.doc - VU scripts for Conversion & General use

rename+P - add a specified prefix

 #!/bin/ksh
 # rename+P - Korn shell script from UVSI stored in: /home/uvadm/sf/util/
 # rename+P - rename an entire directory of filenames
 #          - adding a specified prefix
 #          - inhibited if a specified pattern already present
 #
 echo "rename all filenames in subdir - adding a specified prefix"
 if [[ -d "$1" && -n "$2" && -n "$3" ]]; then :
    else echo "USAGE: rename+P directory prefix inhibitor/all"
         echo "       ======================================="
         echo "example: rename+P datadir raw. raw.  #inhibit if already present"
         echo "         =========================="
    exit 1; fi
 q=$3; if [[ "$3" = "all" ]]; then q="allALL"; fi
 x=0;y=0
 for i in $1/*
 do f=${i##*/}
    let x=x+1
    if [[ "$f" = *"$q"* ]]; then  # if filename contains inhibitor
         echo "file# $x - $1/$f"
    else g=${2}${f}               # insert prefix
         mv -i $1/$f $1/$g        # change filename
         #================
         let y=y+1
         echo "file# $x - $1/$f  - renamed to:  $1/$g"
    fi
 done
 echo "EOD - $y files renamed of $x total in $1"
 exit 0

Goto:   Begin this document End this document UVSI Home-Page

1L1. scripts1.doc - VU scripts for Conversion & General use

renameParens - rename using name from (parens)

 #!/bin/ksh
 # renameParens - Korn shell script from UVSI stored in: /home/uvadm/sf/util/
 # renameParens - rename an entire directory of filenames
 #              - using the (name) extracted from parens
 #
 echo "rename all files in subdir - using (name) extracted from parens"
 if [[ -d "$1" ]]; then :
    else echo "usage: renameParens directory"
         echo "       ======================"
         exit 1; fi
 reply="n"
 until [ "$reply" = "y" ]
 do echo "do you have backup ? y/n"
    read reply
 done
 x=0; y=0
 for df in $1/*
 do f=${df##*/}         # remove any preceding directories
    g=${f#*\(}          # remove left side *(
    h=${g%\)*}          # remove right side  )*
    let x=x+1
    if [[ $h != $f ]]; then
       mv -i $1/$f $1/$h
       #================
       let y=y+1
       echo "file# $x - $1/$f renamed to: $1/$h"
    fi
 done
 echo "total $x files, $y renamed using (name) in parens"
 exit 0

Goto:   Begin this document End this document UVSI Home-Page

1M1. scripts1.doc - VU scripts for Conversion & General use

renameU - translate filenames to UPPER case

 #!/bin/ksh
 # renameU - Korn shell script from UVSI stored in: /home/uvadm/sf/util/
 # renameU - rename an entire directory of filenames to UPPER case
 #
 echo "rename all filenames in subdir - to UPPER case"
 if [ -d "$1" ]; then :
    else echo "usage: renameU directory    <-- arg1 must be a directory"
         echo "       ================="
         exit 1; fi
 #
 reply="n"
 until [ "$reply" = "y" ]
 do echo "will rename all files in $1 to UPPER case OK ? y/n"
    read reply
 done
 #
 x=0; y=0
 for i in $1/*
 do let y=y+1
    f=${i##*/}
    typeset -u g=$f
    if [[ $g != $f ]]; then
       mv -i $1/$f $1/$g
       #================
       let x=x+1
       echo "file# $x (of $y) $1/$f  - renamed to:  $1/$g"
    fi
 done
 echo "total $y files in ${1}, $x renamed to UPPER case"
 exit 0

Goto:   Begin this document End this document UVSI Home-Page

1N1. scripts1.doc - VU scripts for Conversion & General use

renameU1 - translate 1st char of filenames to UPPER case

 #!/bin/ksh
 # renameU1 - Korn shell script from UVSI stored in: /home/uvadm/sf/util/
 # renameU1 - rename an entire directory of filenames to UPPER case
 #            1st letter only, with remainder of filename lower case
 #          - requires ksh newer than 11/16/88 - for ${var:offset:length}
 #
 echo "rename all filenames in subdir - to UPPER case (1st letter only)"
 if [[ ! -d "$1" ]]
    then echo "usage: renameU1 directory   <-- arg1 must be a directory"
         echo "       =================="
         exit 1; fi
 #
 reply="n"
 until [ "$reply" = "y" ]
 do echo "rename all files in $1 to UPPER case (1st letter only) OK ? y/n"
    read reply
 done
 #
 x=0; y=0
 for i in $1/*
 do let x=x+1
    f=${i##*/}
    typeset -u u=$f
    typeset -l l=$f
    u2=${u:0:1}
    l2=${l:1}
    g=${u2}${l2}
    if [[ $1/$f != $1/$g ]]; then
       mv -i $1/$f $1/$g
       #================
       let y=y+1
       echo "file# $x (of $y) $1/$f - renamed to: $1/$g"
    fi
 done
 echo "total $x files in ${1}, $y 1st letter renamed to UPPER case"
 exit 0

Goto:   Begin this document End this document UVSI Home-Page

1O1. scripts1.doc - VU scripts for Conversion & General use

renameX - change specified extension to an alternate

 #!/bin/ksh
 # renameX - Korn shell script from UVSI stored in: /home/uvadm/sf/util/
 # renameX - change a specified extension to a specified alternative
 #           for all files within a directory
 #
 echo "rename all filenames in subdir - replace extension with alternate"
 if [[ -d "$1" && -n "$2" && -n "$3" ]]; then :
    else echo "USAGE:   renameX directory ext1 ext2"
         echo "         ==========================="
         echo "example: renameX cobs .cbl .bat"
         echo "         ======================"
    exit 1; fi
 #
 reply="n"
 until [[ "$reply" = "y" ]]
 do echo "will rename all files in $1 changing ext $2 too $3 OK ? y/n"
    read reply
 done
 #
 x=0;y=0
 for i in $1/*
 do f=${i##*/}
    let x=x+1
    if [[ "$f" == *"$2" ]]; then    # if ext1 present ?
       let y=y+1
       g=${f%$2}                  # remove ext1
       h=$g$3                     # add ext2
       mv -i  $1/$f $1/$h         # rename
       #=================
       echo "file# $x - $1/$f  renamed to:  $1/$h"
    fi
 done
 echo "EOD - $y files renamed of $x total in $1"
 exit 0

Goto:   Begin this document End this document UVSI Home-Page

1P1. scripts1.doc - VU scripts for Conversion & General use

rename-X - remove a specified extension

 #!/bin/ksh
 # rename-X - Korn shell script from UVSI stored in: /home/uvadm/sf/util/
 # rename-X - rename an entire directory of filenames
 #          - removing a specified extension
 #          - may use pattern characters in extension
 #
 echo "rename all filenames in subdir - removing specified extension"
 if [ -d "$1" -a -n "$2" ]; then :
    else echo "usage:  rename-X directory extension  <-- arg1 subdir, arg2 .ext"
         echo "        ============================"
         echo "example: rename-X jcldir .jcl  <--remove .jcl from all jcldir"
         echo "         ===================="
    exit 1; fi
 #
 reply="n"
 until [ "$reply" = "y" ]
 do echo "do you have backup ? y/n"
    read reply
 done
 x=0; y=0
 for i in $1/*
 do f=${i##*/}
    g=${f%$2}
    let x=x+1
    if [[ $g != $f ]]; then
       mv -i $1/$f $1/$g
       #================
       let y=y+1
       echo "file# $x - $1/$f  - renamed to:  $1/$g"
    fi
 done
 echo "total $x files, $y renamed (removing $2)"
 exit 0

Goto:   Begin this document End this document UVSI Home-Page

1Q1. scripts1.doc - VU scripts for Conversion & General use

rename+X - add a specified extension

 #!/bin/ksh
 # rename+X - Korn shell script from UVSI stored in: /home/uvadm/sf/util/
 # rename+X - rename an entire directory of filenames
 #          - adding any specified extension
 #          - inhibited if extension already present (filename contains '.')
 #
 echo "rename all filenames in subdir - adding a specified extension"
 if [[ -d "$1" && -n "$2" ]]; then :
    else echo "USAGE:   rename+X directory extension"
         echo "         ============================"
         echo "example: rename+X jcls .jcl <-- add .jcl to all files in jcls dir"
         echo "         =================="
         echo " - add extension '.jcl' to all files in jcls/ subdir"
    exit 1; fi
 x=0;y=0
 for i in $1/*
 do f=${i##*/}
    let x=x+1
    if [[ "$f" = *\.* ]]; then  # if filename contains inhibitor
         echo "file# $x - $1/$f"
    else g=${f}$2
         mv -i $1/$f $1/$g
         #================
         let y=y+1
         echo "file# $x - $1/$f  - renamed to:  $1/$g"
    fi
 done
 echo "EOD - $y files renamed of $x total in $1"
 exit 0

Goto:   Begin this document End this document UVSI Home-Page

1R1. scripts1.doc - VU scripts for Conversion & General use

renameQQ - remove Quotes

 #!/bin/ksh
 # renameQQ - Korn shell script from UVSI stored in: /home/uvadm/sf/util/
 # renameQQ - rename an entire directory of filenames - removing 'Quotes'
 #
 echo "rename all filenames in subdir - removing 'Quotes'"
 if [ ! -d "$1" ]
    then echo "usage: renameQQ directory  <-- arg1 must be a directory"
         echo "       =================="
         exit 1; fi
 reply="n"
 until [ "$reply" = "y" ]
 do echo "do you have backup ? y/n"
    read reply
 done
 x=0; y=0
 for i in $1/*
 do
    f=$(basename $i)
    echo "f=$f"
    if [[ $f == \'* && $f == *\' ]]; then
       g=${f#\'}              # remove left side 'quote
       h=${g%\'}              # remove right side quote'
       let x=x+1
       mv $1/$f $1/$h
       #=============
       echo "file# $x - $f renamed to: $h"
    fi
 done
 echo "total $x files in $1 renamed (removed quotes)"
 exit 0

Goto:   Begin this document End this document UVSI Home-Page

Part_2 scripts1.doc - Vancouver Utility scripts for Conversion & General use

2A1. Vancouver Utility 'aliases'

'aliases save keystrokes for often repeated commands (alias l='ls -l' is a good example).

Here are the aliases defined in the profiles provided with Vancouver Utilities. See the common_profile listed at ADMjobs.htm#1C3 starting about line 200.

 alias rm='rm -i'              # confirm removes
 alias mv='mv -i'              # confirm renames
 alias cp='cp -i'              # confirm copy overwrites
 alias rmf='rm -f'             # force removes (no prompts)
 alias mvf='mv -f'             # force renames (no prompts)
 alias cpf='cp -f'             # force copies (no prompts)
 alias l='ls -l'               # save keystrokes
 alias more='less'             # less is way better than more
 alias grep='grep -n'          # ensure -n option used on grep
 alias cdd='cd $RUNDATA'       # quick access to data superdir
 alias cdl='cd $RUNLIBS'       # quick access to libs superdir
 alias cdc='cd $CNVDATA'       # quick access to data conversion superdir
 alias cdk='cd $CMPDATA'       # quick access to data conversion superdir
 alias cdb='cd $BACKUP'        # quick access to backup superdir
 alias cdr='cd $RESTORE'       # quick access to restore superdir

notes

We recommend the aliases to prompt for overwrite, such as alias rm='rm -i' Use option '-f' when you have many files (rm -f tmp/*, etc)

Aliases such as cdd='cd $RUNDATA' depend on the prior definitions (in the profiles) of RUNDATA, RUNLIBS, etc in the profiles. This is described in ADMjobs.htm#Part_1.

The result is that programmers will be changed to their testdata,testlibs,etc. But operators would be changed to their proddata, prodlibs, etc. For example the definitions of RUNDATA & RUNLIBS for a programmer might be:

 export RUNDATA=/home/userxx/testdata     <-- private testdata/testlibs
 export RUNLIBS=/home/userxx/testlibs
 export RUNDATA=/p1/apps/testdata         <-- common testdata/testlibs
 export RUNLIBS=/p1/apps/testlibs           - shared by all programmers

Note that some sites may define RUNDATA & RUNLIBS with rather long pathnames & the aliases can save more keystrokes than indicated here.

A major advantage is that administrators can change the locations of data & libraries. The use of environmental variables RUNDATA & RUNLIBS means that programmers & operators do not have to change their usual commands.

Goto:   Begin this document End this document UVSI Home-Page

Part_3 Vancouver Utility scripts for Conversion & General use

listing file & directory names

 3A1. llm - list long & pipe to more
          - similar to alias llm='ls -l | more' (but a script vs an alias)
          - saves keystrokes for this often repeated command

3B1. lla - same as llm, but lists All files including hidden .files

3B2. lld - list directories only (omit files)

3B3. llr - list files & subdirs Recursively (all the way down)

3B4. llt - list files, with the latest First

3B5. lls - list files in Size order

3B6. llu - list files Unsorted

 3C1. lslp - list files & print immediately
           - prints using 'uvlp12' - VU laser printing utility
           - see uvlp12 documented in uvlist.htm
 3D1. spreadA - list filenames 4-up across the page
              - great for JCL/scripts, COBOL programs, copybooks, etc
                (directories with 100's or 1000's of modules)

Goto:   Begin this document End this document UVSI Home-Page

3A1. Vancouver Utility scripts for Conversion & General use

llm - list long & pipe to more

 #!/bin/ksh
 # llm - Korn shell script from UVSI stored in: /home/uvadm/sf/util/
 # llm  - script to list any directory with long option & pipe into more
 #
 #usage with '*' wildcard patterns
 # llm dir/abc*      <-- does not work (will match only 1st occurrence)
 # llm 'dir/abc*'    <-- does work (enclose patterns in single quotes)
 #
 echo "llm - list directory with long option & pipe to more"
 if (($# > 1));then
    echo "usage: llm directory"
    echo "       ============="
    echo "example: llm 'jcls/map*'"
    echo "         ==============="
    echo "- enclose any *wildcard patterns in single quotes"
    exit 1; fi
 #
 if  [[ -z "$1" ]] ; then d="."; else d=$1; fi
 ls -l $d | more
 #==============
 exit 0
 #

Goto:   Begin this document End this document UVSI Home-Page

3B1. Vancouver Utility scripts for Conversion & General use

lla - lists All files including hidden .files

 #!/bin/ksh
 # lla - Korn shell script from UVSI stored in: /home/uvadm/sf/util/
 # lla - script to list directory with ALL & LONG option & pipe into more
 #     - same as llm, but with '-a' option to list hidden .files
 #
 #usage with '*' wildcard patterns
 # lla dir/abc*      <-- does not work (will match only 1st occurrence)
 # lla 'dir/abc*'    <-- does work (enclose patterns in single quotes)
 #
 echo "lla - list All files (including .hidden) & pipe to more"
 if (($# > 1)); then
    echo "usage: lla directory"
    echo "       ============="
    echo "example: lla 'jcls/map*'"
    echo "         ==============="
    echo "- enclose any *wildcard patterns in single quotes"
    exit 1; fi
 #
 if  [[ -z "$1" ]] ; then d="."; else d=$1; fi
 ls -al $d | more
 #===============
 exit 0
 #

Goto:   Begin this document End this document UVSI Home-Page

3B2. Vancouver Utility scripts for Conversion & General use

lld - list directories only (omit files)

 #!/bin/ksh
 # lld - Korn shell script from UVSI stored in: /home/uvadm/sf/util/
 # lld  - script to list directories ONLY with long option & pipe into more
 #
 echo "lld - list Directories Only (long option & pipe to more)"
 if (($# > 1));then
    echo "usage: lld directory[prefix]"
    echo "       ====================="
    echo "example: lld jcl  <-- show alldirs starting with jcl..."
    echo "         ======="
    exit 1; fi
 #
 dp="$1"
 for df in $dp*
   { if [[ -d $df ]]; then
        ls -ld $df
        #=========
     fi
   }
 exit 0
 #

Goto:   Begin this document End this document UVSI Home-Page

3B3. Vancouver Utility scripts for Conversion & General use

llr - list files & subdirs Recursively

 #!/bin/ksh
 # llr - Korn shell script from UVSI stored in: /home/uvadm/sf/util/
 # llr  - list a directory with long & Recursive option & pipe into more
 #      - Recursive option shows contents of all sub-directories
 #
 #usage with '*' wildcard patterns
 # llr dir/abc*      <-- does not work (will match only 1st occurrence)
 # llr 'dir/abc*'    <-- does work (enclose patterns in single quotes)
 #
 echo "llr - list directory with long & Recursive options & pipe to more"
 if (($# > 1));then
    echo "usage: llr directory"
    echo "       ============="
    echo "example: llr 'jcls/map*'"
    echo "         ==============="
    echo "- enclose any *wildcard patterns in single quotes"
    exit 1; fi
 #
 if [[ -z "$1" ]] ; then d="."; else d=$1; fi
 ls -lR $d | more
 #===============
 exit 0
 #

Goto:   Begin this document End this document UVSI Home-Page

3B4. Vancouver Utility scripts for Conversion & General use

llt - list files, latest First

 #!/bin/ksh
 # llt - Korn shell script from UVSI stored in: /home/uvadm/sf/util/
 # llt  - list directory long in reverse date sequence & pipe into more
 #
 #usage with '*' wildcard patterns
 # llt dir/abc*      <-- does not work (will match only 1st occurrence)
 # llt 'dir/abc*'    <-- does work (enclose patterns in single quotes)
 #
 echo "llt - list directory in reverse date sequence & pipe to more"
 if (($# > 1));then
    echo "usage: llt directory"
    echo "       ============="
    echo "example: llt 'jcls/map*'"
    echo "         ==============="
    echo "- enclose any *wildcard patterns in single quotes"
    exit 1; fi
 #
 if [[ -z "$1" ]] ; then  d="."; else d=$1; fi
 ls -lt $d | more
 #===============
 exit 0
 #

Goto:   Begin this document End this document UVSI Home-Page

3B5. Vancouver Utility scripts for Conversion & General use

lls - list files in Size order

 #!/bin/ksh
 # lls - Korn shell script from UVSI stored in: /home/uvadm/sf/util/
 # lls - List directory with options Long sorted by file Size & pipe to more
 #     - also option 'r' for reverse sort (smallest files 1st)
 #
 #usage with '*' wildcard patterns
 # lls dir/abc*      <-- does not work (will match only 1st occurrence)
 # lls 'dir/abc*'    <-- does work (enclose patterns in single quotes)
 #
 echo "lls - list directory with options Long & Unsorted & pipe to More"
 if (($# > 1));then
    echo "usage: lls directory"
    echo "       ============="
    echo "example: lls 'cbls/car*'"
    echo "         ==============="
    echo "- enclose any *wildcard patterns in single quotes"
    exit 1; fi
 #
 if  [[ -z "$1" ]] ; then d="."; else d=$1; fi
 ls -lSr $d | more
 #================
 exit 0
 #

Goto:   Begin this document End this document UVSI Home-Page

3B6. Vancouver Utility scripts for Conversion & General use

llu - list files Unsorted

 #!/bin/ksh
 # llu - Korn shell script from UVSI stored in: /home/uvadm/sf/util/
 # llu - list directory with options Long & Unsorted & pipe into More
 #
 #usage with '*' wildcard patterns
 # llu dir/abc*      <-- does not work (will match only 1st occurrence)
 # llu 'dir/abc*'    <-- does work (enclose patterns in single quotes)
 #
 echo "llu - list directory with options Long & Unsorted & pipe to More"
 if (($# > 1));then
    echo "usage: llu directory"
    echo "       ============="
    echo "example: llu 'jcls/car*'"
    echo "         ==============="
    echo "- enclose any *wildcard patterns in single quotes"
    exit 1; fi
 #
 if  [[ -z "$1" ]] ; then d="."; else d=$1; fi
 ls -lU $d | more
 #===============
 exit 0
 #

Goto:   Begin this document End this document UVSI Home-Page

3C1. Vancouver Utility scripts for Conversion & General use

lslp - list filenames in directory & print immediately

 #!/bin/ksh
 # lslp - Korn shell script from UVSI stored in: /home/uvadm/sf/util/
 # lslp - list directory (long) & print via uvlp12
 #
 echo "lslp - list directory (long) & print via uvlp12"
 if [[ ! -d "$1" ]]; then
    echo "usage: lslp directory"
    echo "       =============="
    exit 9; fi
 #
 if [[ ! -d tmp ]]; then mkdir tmp; fi
 dir=$(basename $1)
 ls -l $1 > tmp/$dir
 files=$(ls $dir | wc -l)
 echo "directory: $dir, files = $files" >>tmp/$dir
 uvlp14 tmp/$dir
 #==============
 exit 0

Note re 'uvlp14'

This is 1 of the few scripts in this section (scripts1.doc) that call a Vancouver Utility vs a unix/linux command. You could change 'uvlp14' to 'lp'.

'uvlp14' is a script that calls the 'uvlist' utility, which is a Vancouver Utility C program that inserts page headings with filename, userid, page#, etc.

These scripts also insert PCL5 commands for laser printing with margins for 3 hole punching & for various cpi (in this case 14 cpi to get 108 chars across).

You can see many more 'uvlp__' scripts at uvlist.htm.

Goto:   Begin this document End this document UVSI Home-Page

3D1. Vancouver Utility scripts for Conversion & General use

spreadA - list filenames 4-up across the page

 #!/bin/ksh
 # spreadA - Korn shell script from UVSI stored in: /home/uvadm/sf/util/
 # spreadA - list directory in multi-columns with options for columns & width
 #
 # - spreadA uses 'ls' to generate a tmp file, input to uvcopy job spread1
 # - uvcopy/spread1 prompts with options for no of columns & column-width
 # - report is created in tmp subdir with headings for dirname & date/time
 # - prompt for report disposition: vi, more, cat, lp, uvlp, etc (or null)
 # - report is left in subdir tmp named the same as the specified directory
 #
 echo "spreadA - list directory in multi-columns, options for columns & width"
 dir="$1"
 if [[ ! -d "$dir" ]]; then
    echo "usage: spreadA directory"
    echo "       ================="
    exit 99; fi
 #
 if [[ ! -d tmp ]]; then mkdir tmp; fi
 ls $dir >tmp/spreadA.tmp  # create file of filenames in specified directory
 #
 # create full path name of directory, to show on report (if not already)
 if [[ $dir = /* ]]; then DIR=$dir; else DIR=${PWD}/$dir; fi
 export DIR=$DIR           # export full path dirname for uvcopy job hdngs
 export JOBID=spreadA      # export JOBID (spreadA) for uvcopy job hdngs
 # use basename of directory as uvcopy job output filename in tmp
 dirfile=$(basename $dir)
 #
 uvcopy spread1,fili1=tmp/spreadA.tmp,filo1=tmp/${dirfile}.4up,uop=c18n4
 #======================================================================
 exit 0
Note
  • this is 1 of the few scripts in this scripts1.doc that call a
    Vancouver Utility vs a unix/linux command.
  • see notes about 'uvcopy' on the next page.

Goto:   Begin this document End this document UVSI Home-Page

3D2. Vancouver Utility scripts for Conversion & General use

script spreadA calls 'uvcopy job' spread1

'uvcopy' is Vancouver Utility C program for general purpose data manipulation. It is an interpreter for the instructions in a separate instruction file. 'spread1' is found via 'PFPATH', defined in the profile ('ADMjobs.doc#1C3').

The 'spreadA' script (above) uses 'ls' to capture all filenames in a tmp/file, and calls uvcopy job 'spread1' to format the filenames across the page.

Note the options 'uop=c18n4' at the end of the uvcopy command line above. 'c18' sets Column width to 18 & 'n4' sets Number of columns to 4.

See the uvcopy job 'spread1' listed at UVjobs1.htm#U6.

Also see sample operating instructions & a sample report at UVjobs1.htm#L1.

uvcopy can perform complex data manipulations with very few instructions. It is an essential part of the mainframe conversions because it can do many things not possible with the standard unix/linux utilities (such as processing packed decimal fields & handling Indexed files compatible with Micro Focus COBOL). See more about uvcopy at uvcopy1.htm.

Goto:   Begin this document End this document UVSI Home-Page

Part_4 Vancouver Utility scripts for Conversion & General use

scripts to process all files in directory

 4A1. alldiff - script to repeat 'diff' for all file pairs in 2 directories
              - 'diff' is a marvelous unix/linux utility for text files
              - alldiff is great for verifying changes in conversion techniques
              - confirm desired changes & no unintended changes
 4B1. allcmp - script to repeat 'cmp' for all file pairs in 2 directories
             - 'cmp' compares any type of file (packed/binary fields, no LFs)
             - but very poor at indicating differences (1 byte per line)
             - follow with 'uvcmp' utilities to show record pairs with * diffs
               (see CMPjobs.htm)
 4C1. alldos2unix - copy all files to a 2nd subdir, removing Carriage-Returns
                  - Windows/DOS text records terminated with CR/LF x'0D0A'
                  - Unix/Linux text records terminated with just LF x'0A'

4C2. allunix2dos - copy all files to a 2nd subdir, inserting Line-Feeds

 4D1. rmzf - remove all zero-length (empty) files from a directory
           - use after mass processing that may produce empty files
             example - converting copybooks to record layouts (cobmaps)
                     - no output for procedure copybooks
 4E1. allrm - remove all files in a directory
            - use when number of files exceed unix/linux limits
              (was required for earlier unix versions with lower limits)
            - also see allcp, allmv, etc
 4F1. allcancel - cancel all printer requests (spooled by 'lp') for current user
                - does an lpstat to get request-ids & cancels them
 4G1. rmold1 - remove files older than a specified number of days
             - prompts y/n for each file
 4G2. rmold2 - remove files older than a specified number of days
             - lists all old files & prompts for each old file to be removed
 4G3. rmold3 - remove files older than a specified number of days
             - lists all old files & prompts once to remove all old files
             - rmold1,2,3 find files on any level within a directory tree
 4H1. vis    - edit multiple files in directory in Size order
             - arg1 = directory, arg2 = no of files (default 5)

Goto:   Begin this document End this document UVSI Home-Page

4A1. scripts to process all files in directory

alldiff - compare all text files in 2 directories

 #!/bin/ksh
 # alldiff - Korn shell script from UVSI stored in: /home/uvadm/sf/util/
 # alldiff - script to compare all text files in 1 directory to a 2nd directory
 #         - bypass non-text files & provide audit trail with file-counts
 #
 # alldiff variations:
 #*alldiff  - displays filename only if differences exist
 # alldiff1 - displays filename even if no differences
 # alldiff2 - same as alldiff, but in addition
 #          - redirects output to tmp/dir2.dif & prompts for disposition
 #     note - this is the author's preference
 #
 echo "alldiff - compare all text files in 1 directory to a 2nd directory"
 if [[ -d "$1" && -d $2 ]]; then :
 else echo "usage: alldiff dir1 dir2"
      echo "       ================="
      echo "example: alldiff cbls.old cbls"
      echo "         ====================="
      echo " - confirm updates in cobol source dir"
      exit 1; fi
 x=0; y=0;
 for i in $1/*
 do
   let x=x+1
   typ=$(file $i)
   if [[  $typ == *text* || $typ == *script* || $typ == *spreadsheet* ]]
      then f=${i##*/}
           diff -b $1/$f $2/$f
           #==================
           if [[ $? -gt 0 ]]; then
              echo "diff file# $x - $1/... vs $2/$f"
              echo " "
              let y=y+1
           fi
      else echo "    file# $x $i - NOT a text/script file"
   fi
 done
 echo "$y different of $x files compared $1 to $2"
 exit

Goto:   Begin this document End this document UVSI Home-Page

4B1. scripts to process all files in directory

allcmp - compare all packed/binary files in 2 directories

 #!/bin/ksh
 # allcmp - Korn shell script from UVSI stored in: /home/uvadm/sf/util/
 # allcmp - script to execute the UNIX 'cmp' command to compare
 #          corresponding files in 2 directories
 #
 #usage:  allcmp dir1 dir2 ['pattern']     (pattern defaults to *)
 #        ============================
 #
 #example#1: allcmp tmp1 tmp2         - compare all files in tmp1 & tmp2
 #           ================
 #
 #example#1: allcmp tmp1 tmp2 'a*'    - compare all files in tmp1 & tmp2
 #           =====================      whose names begin with 'a'
 #
 echo "allcmp - compare files in 2 directories, using unix 'cmp'"
 echo "- for files with packed/binary & no LineFeeds (use diff for text files)"
 #
 if [[ -d "$1" && -d "$2" ]]; then :
    else echo "usage: allcmp dir1 dir2"
         echo "       ================"
         echo "example1: allcmp gl.old gl"
         echo "          ================"
         echo "example2: allcmp mstr.old mstr 'gl*'"
         echo "          =========================="
         echo " - arg3 optional prefix* must be in single quotes"
         exit 99; fi
 #
 pat='*'            # default pattern to '*'
 if [[ -n "$3" ]]; then pat="$3"; fi
 x=0;y=0;
 for i in $1/$pat
   { let x=x+1
     f=${i##*/}
     cmp $1/$f $2/$f
     #==============
     if (($? != 0)); then
        echo "file# $x cmp $1/$f $2/$f"
        echo " ";       # generate blank line to highlight diffs
        let y=y+1
     fi
   }
 echo "$y mismatches of $x total files compared in $1 & $2"
 exit 0

Goto:   Begin this document End this document UVSI Home-Page

4C1. scripts to process all files in directory

alldos2unix - copy files removing Carriage-Returns

 #!/bin/ksh
 # alldos2unix - Korn shell script from UVSI stored in: /home/uvadm/sf/util/
 # alldos2unix - script to copy all files from 1 directory to a 2nd directory
 #           - converting terminators from DOS (CR+LF) to unix (LF only)"
 echo "alldos2unix - copy all files from 1 directory to a 2nd directory"
 echo "            - converting terminators from DOS (CR+LF) to unix (LF only)"
 #
 if [[ -d "$1" && -d $2 ]]; then :
 else echo "usage: alldos2unix indir outdir  <-- arg1 & arg2 must be subdirs"
      echo "       ========================"
 exit 1; fi
 x=0;
 for i in $1/*
 do
   f=${i##*/}
   let x=x+1
   dos2unix -n $1/$f $2/$f
   #======================
 done
 echo "total $x files copied from $1 to $2 (changing CR+LF to LF only)"
 chmod 664 $2/*
 exit 0

Goto:   Begin this document End this document UVSI Home-Page

4C2. scripts to process all files in directory

allunix2dos - copy files inserting Line-Feeds

 #!/bin/ksh
 # allunix2dos - Korn shell script from UVSI stored in: /home/uvadm/sf/util/
 # allunix2dos - script to copy all files from 1 directory to a 2nd directory
 #           - converting terminators from unix (LF only) to DOS (CR+LF)
 echo "allunix2dos - copy all files from 1 directory to a 2nd directory"
 echo "            - converting terminators from unix (LF only) to DOS (CR+LF)"
 #
 if [[ -d "$1" && -d $2 ]]; then :
 else echo "usage: allunix2dos indir outdir  <-- arg1 & arg2 must be subdirs"
      echo "       ========================"
 exit 1; fi
 x=0;
 for i in $1/*
 do
   f=${i##*/}
   let x=x+1
   unix2dos -n $1/$f $2/$f
   #======================
 done
 echo "total $x files copied from $1 to $2 (changing LF to CR+LF)"
 chmod 664 $2/*
 exit 0

Goto:   Begin this document End this document UVSI Home-Page

4D1. scripts to process all files in directory

rmzf - remove zero-length (empty) files from a directory

 #!/bin/ksh
 # rmzf - Korn shell script from UVSI stored in: /home/uvadm/sf/util/
 # rmzf - script to remove zero-length files from a directory
 #
 # use after jobs that process 100's of files
 # but produce output for only a small no of the input files
 # this will remove the zero-length files from the directory
 # many other methods wont work because you get arg list too long
 #
 echo "rmzf - remove all zero-length (empty) files in directory"
 if [[ ! -d "$1" ]]; then
    echo "usage: rmzf directory"
    echo "       =============="
    exit 99; fi
 #
 x=0; y=0
 for i in $1/*
 do
   if [[ ! -s $i ]]; then
      rm -f $i
      #=======
      let x=x+1
   fi
   let y=y+1
 done
 echo "removed $x files of $y files in directory $1"
 exit

Goto:   Begin this document End this document UVSI Home-Page

4E1. scripts to process all files in directory

allrm - remove all files in a directory

 #!/bin/ksh
 # allrm - Korn shell script from UVSI stored in: /home/uvadm/sf/util/
 # allrm - script to remove all files from a directory
 #       - use if no of files greater than allowed by UNIX shell (512,1024,?)
 #         (when you get errmsg "arg list too long")
 #       - also provides audit trail with file-counts
 #
 #usage: allrm directory
 #       ===============
 #
 reply="n"
 until [ "$reply" = "y" ]
   do echo "Are you sure you want to remove files from $1 ? y/n"
      read reply
   done
 #
 if [ -d "$1" ]; then :
 else echo "USAGE: allrm dir1 "
 exit 1; fi
 x=0;
 for i in $1/*
   { let x=x+1
     echo "removing file# $x - $i "
     rm -f $i
     #=======
   }
 echo "total $x files removed from $1"
 exit

Goto:   Begin this document End this document UVSI Home-Page

4F1. scripts to process all files in directory

allcancel - cancel all printer requests for current user

 #!/bin/ksh
 # allcancel - Korn shell script from UVSI stored in: /home/uvadm/sf/util/
 # allcancel - cancel all printer requests for the current user
 #           - no arguments required
 #           - very handy when you need to cancel all your print requests
 #             (because cancel does not provide an option for all requests)
 #
 if [[ ! -d tmp ]]; then mkdir tmp; fi  # if tmpdir not present, make it
 #
 lpstat >tmp/allcan1                    # request-id is 1st word on each line
 cut -f1 -d' ' tmp/allcan1 >tmp/allcan2 # cut 1st word to separate file
 #
 # now open the file & read line contents into variable $reqid
 exec 3< tmp/allcan2                    # open file for reading
 while read -u3 reqid                   # read current request id
   do
      cancel $reqid                     # cancel request id
      #============
   done
 exec 3<&-                              # close the file
 exit 0

Goto:   Begin this document End this document UVSI Home-Page

4G1. scripts to process all files in directory

rmold1 - remove files older than x days, prompt each

 #!/bin/ksh
 # rmold1 - Korn shell script from UVSI stored in: /home/uvadm/sf/util/
 # rmold1 - remove files from a specified directory (& all subdirs),
 #          that are older(+) or newer(-) than a specified number of days
 #        - prompts y/n for each file to be removed
 #        - 3 variations of this script as follows:
 #
 #*rmold1 (this script) - prompts y/n for each old file to be removed
 # rmold2 - lists all old files & prompts for each old file to be removed
 # rmold3 - lists all old files & prompts once to remove all old files
 #
 if [[ -d "$1" && -n "$2" ]]; then :
    else echo "usage: rmold1 directory +days"
         echo "       ======================"
         echo "example rmold1 history +730  <-- remove files over 2 yrs old"
         echo "        ==================="
         exit 1; fi
 #
 find $1 -mtime $2 -exec rm -i {} \;
 #==================================
 exit 0

Goto:   Begin this document End this document UVSI Home-Page

4G2. scripts to process all files in directory

rmold2 - remove old files, list all & prompt each

 #!/bin/ksh
 # rmold2 - Korn shell script from UVSI stored in: /home/uvadm/sf/util/
 # rmold2 - remove files from a specified directory (& all subdirs),
 #          that are older(+) or newer(-) than a specified number of days
 #        - lists all old files & prompts y/n for each file to be removed
 #        - prompts y/n for each file to be removed
 #        - 3 variations of this script as follows:
 #
 # rmold1 - prompts y/n for each old file to be removed
 #*rmold2 (this script) - lists all old files & prompts for each file to remove
 # rmold3 - lists all old files & prompts once to remove all old files
 #
 if [[ -d "$1" && -n "$2" ]]; then :
    else echo "usage: rmold2 directory +days"
         echo "       ======================"
         echo "example: rmold2 history +730  <-- remove files over 2 yrs old"
         echo "         ==================="
         exit 1; fi
 #
 find $1 -mtime $2 -exec ls -l {} \;  #<-- list all old files
 #==================================
 #
 find $1 -mtime $2 -exec rm -i {} \;  #<-- remove old files with prompt for each
 #==================================
 exit 0

Goto:   Begin this document End this document UVSI Home-Page

4G3. scripts to process all files in directory

rmold3 - remove old files, list all & prompt once for all

 #!/bin/ksh
 # rmold3 - Korn shell script from UVSI stored in: /home/uvadm/sf/util/
 # rmold3 - remove files from a specified directory (& all subdirs),
 #          that are older(+) or newer(-) than a specified number of days
 #        - does not prompt y/n for each file to be removed (rmold1 for prompt)
 #          but lists files to be removed & prompts once for all to be removed
 #        - 3 variations of this script as follows:
 #
 # rmold1 - prompts y/n for each old file to be removed
 # rmold2 - lists all old files & prompts for each file to remove
 #*rmold3 (this script) - lists all old files & prompts once to remove all old
 #
 if [[ -d "$1" && -n "$2" ]]; then :
    else echo "usage: rmold3 directory +days"
         echo "       ======================"
         echo "example: rmold3 history +730  <-- remove files over 2 yrs old"
         echo "         ==================="
         exit 1; fi
 #
 # list files to be removed, prompt once y/n, then execute remove all
 #
 find $1 -mtime $2 -exec ls -l {} \;  #<-- list all old files
 #==================================
 #
 reply="x"
 until [[ "$reply" == "y" || "$reply" == "n" ]]
   do echo "remove files (listed above) from $1 ? y/n"
      read reply
   done
 #
 if [[ "$reply" = "y" ]]; then
    find $1 -mtime $2 -exec rm -f {} \;  #<-- remove all old files (no prompts)
    #==================================
 fi
 exit 0

Goto:   Begin this document End this document UVSI Home-Page

4H1. scripts to process all files in directory

vis - edit multi files in directory in Size order

 #!/bin/ksh
 # vis - Korn shell script from UVSI stored in: /home/uvadm/sf/util/
 # vis - vi/edit multiple files in directory in Size order
 #
 #usage with '*' wildcard patterns
 # vis dir/abc*      <-- does not work (will match only 1st occurrence)
 # vis 'dir/abc*'    <-- does work (enclose patterns in single quotes)
 #
 echo "vis - vi/edit multiple files in directory in Size order"
 if (($# > 2));then
    echo "usage: vis directory/* limit# <-- edit multi files in directory"
    echo "       ======================     in size sequence (quit after limit#)"
    echo "example: vis 'jcls/jar*' 3    <-- edit 3 smallest jar* files in jcls/"
    echo "         ================="
    echo "- enclose any *wildcard patterns in single quotes"
    echo "- ':q'uit for next file (not ':n' since separate vi's)"
    echo "- limit default is 5 (since you have to quit each file to end script)"
    exit 1; fi
 #
 if [[ -z "$1" ]]; then d="."; else d=$1; fi
 if [[ $d == "." ]]; then td=td; else td=${d%/*}; fi
 ls -Sr $d >tmp/$td      # create file of filenames in Size sequence
 if [[ -z "$2" ]]; then limit=5; else limit=$2; fi
 count=0;                # init count to end at limit
 exec 3< tmp/$td         # open file for reading
 while read -u3 file     # read next filename
   do
     vi $d/$file         # edit current file
     #==========
     ((count+=1))
     if ((count>=limit)); then break; fi
   done
 exec 3<&-               # close file of filenames
 exit 0
 #

Goto:   Begin this document End this document UVSI Home-Page

Part_5 Vancouver Utility scripts for Conversion & General use

Counting files in directories

 5A1. countf - count all files in a directory
             - lists filenames with sequence numbers & a total line
 5B1. countfd - count all files in a super-directory with multiple subdirs
              - totals for each subdir & grand-total for all subdirs

5C1. countfl - counts files & lines in each file in a specified directory

5D1. countflp - counts files & lines in each file matching a specified prefix

 5E1. statdir1 - display disc usage for all files&subdirs in specified directory
               - shows total files & total KB in each subdir
               - sample report shown

Goto:   Begin this document End this document UVSI Home-Page

5A1. Counting files in directories

countf - count all files in a directory

 #!/bin/ksh
 # countf - Korn shell script from UVSI stored in: /home/uvadm/sf/util/
 # countf - count files in a directory (while listing)
 #        - if text file, show no of lines in file
 #        - option to count only files matching suffix supplied by arg#2
 #
 echo "countf - count files in a directory (while listing)"
 if [ -d "$1" ]; then :
    else echo "usage: countf directory [suffix]"
         echo "       =========================="
         echo "usage: countf cblx .err"
         echo "       ================"
         echo " count files in cblx with .err suffixes"
         exit 1; fi
 #
 x=0;y=0
 for i in $1/*
 do
    if [[ -f $i ]]; then
       let x=x+1
       f=${i##*/}
       g=${f%$2}
       if [ "$2" = "" -o "$g" != "$f" ]; then let y=y+1; fi
       echo "file# $y $i"
       #=================
    fi
 done
 echo "$x total files in directory $1"
 if [ -n "$2" ]; then echo "$y files with matching suffix $2"; fi
 return $x

Goto:   Begin this document End this document UVSI Home-Page

5B1. Counting files in directories

countfd - count files in a super-directory with multiple subdirs

 #!/bin/ksh
 # countfd - Korn shell script from UVSI stored in: /home/uvadm/sf/util/
 # countfd - count files by sub-directory within a specified parent directory
 #
 # - This script is intended to help prevent inadvertent loss or addition
 #   to directories of programs, scripts, data,or other critical files.
 # - You could run this script with your daily backup & maintain a few weeks
 #   of the file count reports, which could be reviewed when required.
 # - You could compare today's report with yesterday's report visually or
 #   using 'diff' if you have a large number of subdirectories
 #   (the only difference should be the report name & the date)
 # - this assumes the parent directory contains only sub-directories
 #   (any files directly beneath the parent directory are ignored)
 #
 #example#2: countfd parentdir >cnt1/$(date +%y%d%m:%H%M)
 #           ===========================================
 #           - use this format if executing within a backup script
 #           - the 'cnt1' directory could be copied to 'cnt2' at the
 #             end of the month & cnt1 cleared (via cron processing)
 #
 echo "#countfd - file counts by subdir in $1 $(date +%y%d%m:%H%M)"
 if [[ ! -d "$1" ]]; then
    echo "usage: countfd parentdirectory"
    echo "       ======================="
    echo "example: countfd proddata >proddata_counts
    echo "         ================================="
    exit 99; fi
 #
 typeset -RZ5 cnt=0; fcnt=0; dcnt=0;
 #
 for dir in $1/*
 do if [[ ! -d $dir ]]; then continue; fi
    cnt=$(ls $dir | wc -w)
    #=====================
    echo "$cnt files in subdir $dir"
    let fcnt=$fcnt+$cnt
    let dcnt=$dcnt+1
 done
 echo "$fcnt files in $dcnt subdirs of $1 $(date +%y%d%m:%H%M)"
 exit 0

Goto:   Begin this document End this document UVSI Home-Page

5C1. Counting files in directories

countfl - counts files & lines in each file

 #!/bin/ksh
 # countfl - Korn shell script from UVSI stored in: /home/uvadm/sf/util/
 # countfl - count files in a directory (while listing)
 #         - if text file, show no of lines in file
 #
 echo "countfl - count files & lines in a directory"
 if [ -d "$1" ]; then :
    else echo "usage: countfl directory"
         echo "       ================="
         echo " - arg1 must be a directory"
    exit 1; fi
 #
 integer x=0 y=0 tl=0 ln2=0
 for i in $1/*
 do
    let x=x+1
    f=${i##*/}
    g=${f%$2}
    ln1=$(wc -l $i)   # get line count
    ln2=${ln1% *}     # remove right side filename (to blank separator)
 #  ln3=${ln2## *}    # remove left side blanks (did not work? but acum OK)
 #  echo "ln1=$ln1 ln2=$ln2 ln3=$ln3"   # debug investigation
    echo "file#$x $ln2 $i";  # display file#, lines,& filename
    ((tl+=ln2))       # accumulate total lines
 done
 echo "Totals: $x files & $tl lines in directory $1"
 exit 0

Goto:   Begin this document End this document UVSI Home-Page

5D1. Counting files in directories

countflp - counts files & lines in files matching a prefix

 #!/bin/ksh
 # countflp - Korn shell script from UVSI stored in: /home/uvadm/sf/util/
 # countflp - count files in a directory (while listing)
 #          - if text file, show no of lines in file
 #          - option to count only files matching suffix supplied by arg#2
 #
 echo "countflp - count files & lines in directory (optionally matching prefix)"
 if [ -d "$1" ]; then :
    else echo "usage: countflp directory [suffix]"
         echo "       ==========================="
         echo "- arg1=directory, arg2=prefix file select (optional)"
    exit 1; fi
 #
 integer x=0 y=0 tl=0 ln2=0
 for i in $1/*
 do
   let x=x+1
   f=${i##*/}
   g=${f%$2}
   if [[ "$2" == "" || "$f" == "$2"* ]]; then
      let y=y+1
      ln1=$(wc -l $i)   # get line count
      ln2=${ln1% *}     # remove right side filename (to blank separator)
      echo "file#$y $ln2 $i";  # display file#, lines,& filename
      ((tl+=ln2))       # accumulate total lines
   fi
 done
 echo "Totals: $x files & $tl lines in directory $1"
 if [ -n "$2" ]; then echo "$y files with matching suffix $2"; fi
 exit 0

Goto:   Begin this document End this document UVSI Home-Page

5E1. Counting files in directories

statdir1 - total files & KB for all subdirs/files in superdir

This script should be very useful to any unix/linux site:

  1. Helps control disc storage used. Note the sample report shown below for all user /home/... dirs. You can quickly spot any users with extreme Total KB of storage.

  2. Helps verify results of batch runs, you might know how many files & approx how much disc usage there should be for each subdir.

  3. Helps maintain the integrity of your directories & files. The report shows if there are any subdirs within a subdir, which might be a problem if you have batch jobs that process all entries in a directory & might be upset by the appearance of an unintended subdir created by mistake.

Here is the report I created for all /home/... dirs on my machine:


 statdir1 /home      <-- call script, arg1 is directory to be examined
 ==============

statdir1 - sample report

 stats/home.rpt - FileCounts & DiscUsage for SubDirs in ParentDir: /home
 #1 Files=0000063 SubDirs=0049 TotKB=0004308 - /home/appsadm
 #2 Files=0000126 SubDirs=0022 TotKB=0001180 - /home/aquitec
 #3 Files=0000266 SubDirs=0057 TotKB=0018216 - /home/berks
 #4 Files=0000036 SubDirs=0037 TotKB=0000372 - /home/callatay
                  - - - - - etc - - - - -
 #82 Files=0003280 SubDirs=0252 TotKB=0060484 - /home/uvadm
 #83 Files=0003995 SubDirs=0297 TotKB=0070032 - /home/uvext
 #84 Files=0000015 SubDirs=0006 TotKB=0000100 - /home/uvtest1
 #85 Files=0000407 SubDirs=0079 TotKB=0003168 - /home/vsetest
 Total Dirs=85, Files=33711, SubDirs=3646, KB=1550852, for ParentDir=/home

You can rerun for homedirs using a lot of storage, for example:


 statdir1 /home/uvadm     <-- rerun for selected homedirs
 ====================

See the 'statdir1' script listed on the next page --->

Goto:   Begin this document End this document UVSI Home-Page

5E2. Counting files in directories

statdir1 - total files & KB for all subdirs/files in superdir

 #!/bin/ksh
 # statdir1 - Korn shell script from UVSI stored in: /home/uvadm/sf/util/
 # statdir1 - report file count & total KB for each subdir in a parent dir
 #          - display 1 line per subdir & write report into stats/statdir1.rpt
 #            (subdir 'stats' must be present in cwd to receive report)
 #          - ignore any files in the parent dir
 #          - by Owen Townsend, November 2007
 #
 if [[ -d "$1" && -d stats ]]; then :
    else echo "usage: statdir1 parentdirectory"
         echo "       ========================"
         echo "- arg1 must be a directory with subdirs to be analyzed"
         echo "- subdir 'stats' must exist in cwd to receive report"
         echo "- report name will be stats/ParentDir.rpt"
         exit 99; fi
 #
 pd="$1";               #capture parentdir name
 pdb=$(basename $pd)    #extract basename ParentDir for rpt name in stat subdir
 statrpt=stats/$pdb.rpt #setup output report name
 echo "$statrpt - FileCounts & DiscUsage for SubDirs in ParentDir: $pd"
 echo "$statrpt - FileCounts & DiscUsage for SubDirs in ParentDir: $pd">$statrpt;
 integer lines=0;       #init count subdirs in pd
 integer pdsdc=0;       #init count total files in parentdir
 integer pdsdu=0;       #init count total disc-usage in parentdir
 integer pdssdc=0;      #init count total subsubdirs in parentdir
 typeset -RZ7 sdcnz     #set fixlth for file count (align display)
 typeset -RZ7 sdduz     #set fixlth for total KB (keep display aligned)
 typeset -RZ4 ssdcnz    #set fixlth for SubSubDirs
 #
 for sd in $pd/*
   { # we expect ParentDir to have no files (all files s/b in the subdirs)
     # Indicate any files within ParentDir with 'File' vs 'Files'
     if [[ -d $sd ]]; then Files="Files"; else Files="File"; fi
     ((lines+=1))                #increment count of subdirs within parentdir
     sdcnt=$(find $sd -type f | wc -l)  # capture file count string
     sdcnz=${sdcnt##* }                 # drop leading blanks
     sddus=$(du -s $sd | tr '\t' ' ')   # capture du string, trnslt tab=space
     sdduz=${sddus%% *}                 # drop blank(tab) & subdir-name
     ssdcnt=$(find $sd/* -type d | wc -l) # capture sub-subdir count string
     ssdcnz=${ssdcnt##* }               # drop leading blanks
     echo "#$lines $Files=$sdcnz SubDirs=$ssdcnz TotKB=$sdduz - $sd"
     echo "#$lines $Files=$sdcnz SubDirs=$ssdcnz TotKB=$sdduz - $sd" >>$statrpt
     ((pdsdc+=sdcnz))            #acum total files in parentdir
     ((pdsdu+=sdduz))            #acum total Disc-Usage in parentdir
     ((pdssdc+=ssdcnz))          #acum total subsubdirs in parentdir
   }
 echo "Total Dirs=$lines, Files=$pdsdc, SubDirs=$pdssdc, KB=$pdsdu, for ParentDir=$pd"
 echo "Total Dirs=$lines, Files=$pdsdc, SubDirs=$pdssdc, KB=$pdsdu, for ParentDir=$pd" >>$statrpt
 echo "view   $statrpt    <-- view report"
 echo "uvlp12 $statrpt    <-- print report"
 exit 0

Goto:   Begin this document End this document UVSI Home-Page

Part_6 Vancouver Utility scripts for Conversion & General use

copying & sorting files from 1 dir to a 2nd dir

 6A1. copycpio1 - copy all files & subdirs (recursively) from dir to dir
                - foolproof, ensures you are in input dir & outdir empty
 6B1. copycpio2 - copy all files & subdirs (recursively) from dir to dir
                - foolproof, ensures you are in output dir & it is empty

6C1. copydate - copy a file to a directory, appending a date-stamp on the file

 6D1. cpnew1 - copy files from 1 directory to a 2nd directory
               that are newer than a specified number of days
 6D2. cpnew2 - copy files from 1 directory to a 2nd directory whose last
               modification times are within a specified date range
               specify dates as for the 'touch' command--> YYMMDDhhmm
 6E1. sortcpio - copy all files & subdirs (recursively) from dir to dir
               - sorting on file & directory names
               - so filenames will be alphabetic on all utilities
                 (not just for 'ls' commands which sort filenames internally)

6F1. sortall - sort all text files in a directory outputting to a 2nd directory

Goto:   Begin this document End this document UVSI Home-Page

6A1. copying & sorting files from 1 dir to a 2nd dir

copycpio1 - copy subdirs/files from indir to outdir

 #!/bin/ksh
 # copycpio1 - Korn shell script from UVSI stored in: /home/uvadm/sf/util/
 # copycpio1 - copy a directory tree to a 2nd directory
 #           - input may have sub-directories to any level
 #           - output will have exactly the same tree structure
 #           - you must be in input directory
 #           - output directory must be empty
 #           - you must specify full pathname of indir & outdir
 #           - fail-safe, paranoid script
 #           - also see copycpio2, similar to this *copycpio1, except:
 #*copycpio1 - requires you to be in input directory
 # copycpio2 - requires you to be in output directory
 #
 # Example - copy /p2/proddata/... to /p3/backup/proddata
 # 1. cd /p2/proddata                  <-- change to input directory
 # 2. ls -l /p3/backup/proddata | more <-- ensure outdir OK to erase
 # 3. rm -rf /pr/backup/proddata/*     <-- clear output directory
 # 4. copycpio1 /p2/proddata /p3/backup/proddata <-- do it
 #    ==========================================
 #
 d1="$1"; d2="$2";
 if [[ -d "$d1" && -d "$d2" ]]; then :
    else echo "usage: copycpio1 indir outdir"
         echo "       ======================"
         echo " - arg1 & arg2 must be directories (input & output)"
         exit 91; fi
 #
 dpath=$(pwd)                      # capture current directory path
 if [[ $dpath != $d1 ]]
    then echo "you must be in the input directory $d1";
          exit 92; fi
 #
 ls $2 >/tmp/copycpio_emptytest
 if [[ -s /tmp/copycpio_emptytest ]]
    then echo "the output directory must be empty $d2";exit 93; fi
 #
 echo "copy $d1 to $d2 OK ? (or kill)"; read reply
 cd $d1                          # <-- change to indir
 find . -print | cpio -pdmv $d2  # <-- copy all files to outdir
 #=============================
 exit 0

Goto:   Begin this document End this document UVSI Home-Page

6B1. copying & sorting files from 1 dir to a 2nd dir

copycpio2 - copy subdirs/files to outdir from indir

 #!/bin/ksh
 # copycpio2 - Korn shell script from UVSI stored in: /home/uvadm/sf/util/
 # copycpio2 - copy a directory tree to a 2nd directory
 #           - input may have sub-directories to any level
 #           - output will have exactly the same tree structure
 #           - you must be in output directory & it must be empty
 #           - you must specify full pathname of outdir & it must match .
 #           - fail-safe, paranoid script
 #           - also see copycpio1, similar to this *copycpio2, except:
 # copycpio1 - requires you to be in input directory
 #*copycpio2 - requires you to be in output directory
 #
 # Example - copy /p2/proddata/... to /p3/backup/proddata
 # 1. cd /p3/backup/proddata         <-- change to output directory
 # 2. ls -l | more                   <-- ensure outdir OK to erase
 # 3. rm -rf *                       <-- clear output directory
 # 3a. rm -rf /p3/backup/proddata/*  <-- safer (avoid unqualified '*')
 # 4. copycpio2 /p2/proddata /p3/backup/proddata <-- do it
 #    ==========================================
 #
 d1="$1"; d2="$2";
 if [[ -d "$d1" && -d "$d2" ]]; then :
    else echo "usage: copycpio2 indir outdir"
         echo "       ======================"
         echo " - arg1 & arg2 must be directories (input & output)"
         exit 91; fi
 #
 dpath=$(pwd)                      # capture current directory path
 if [[ $dpath != $d2 ]]
    then echo "you must be in output directory (& it must be empty) $d2";
          exit 92; fi
 #
 ls . >/tmp/copycpio_emptytest
 if [[ -s /tmp/copycpio_emptytest ]]
    then echo "the current directory (output) must be empty $d2";exit 93; fi
 #
 echo "copy $d1 to current dir $d2 OK ? (or kill job)"; read reply
 cd $d1                          # <-- change to indir
 find . -print | cpio -pdmv $d2  # <-- copy all files to outdir
 #=============================
 exit 0

Goto:   Begin this document End this document UVSI Home-Page

6C1. copying & sorting files from 1 dir to a 2nd dir

copydate - copy file to a directory, appending date-stamp

 # copydate - copy a file, appending a date stamp
 #          - by Owen Townsend, UV Software, Jan30/06
 # copydatetime - alternative script if you want time as well as date
 #
 #usage: copydate inputfile outputdirectory
 #       ==================================
 #       - arg1 must be a file, arg2 must be a directory
 #
 #example: copydate data/test1 tmp
 #         =======================
 #         - output would be: tmp/test1_yymmdd
 #
 if [[ -f "$1" && -d "$2" ]]; then :
 else echo "usage: copydate inputfile outputdirectory"
      echo "       =================================="
      echo "       - arg1 must be a file, arg2 must be a directory"
      exit 1; fi
 #
 fil="$1"; dir="$2";          # capture input-file-name & output-directory-name
 fbn=$(basename $fil)         # extract file basename, dropping any directories
 fbndt=${fbn}_$(date +%y%m%d) # append date stamp
 #
 cp $fil $dir/$fbndt          # copy inputfile to outdir appending date stamp
 #===================
 exit 0

Goto:   Begin this document End this document UVSI Home-Page

6D1. copying & sorting files from 1 dir to a 2nd dir

cpnew1 - copy files to a 2nd subdir newer than x days

 #!/bin/ksh
 # cpnew1 - Korn shell script from UVSI stored in: /home/uvadm/sf/util/
 # cpnew1 - copy files from 1 directory to a 2nd directory
 #          that are newer than a specified number of days
 #
 #usage:  cpnew1 indir outdir days
 #        ========================
 #
 #note - this script illustrates reading text lines from a file
 #       (a powerful feature of the KORN shell)
 #       'exec 3<' to open, 'read -u3 field' to read, 'exec 3<&-' to close
 #
 if [ -d "$1" -a -d "$2" -a -n "$3" ]; then :
 else echo "USAGE: cpnew1 indir outdir days"; exit 1; fi
 #
 # create tmp dir in current dir if not already present
 if [[ ! -d tmp ]]; then mkdir tmp; fi
 #
 # create list of filenames newer than specified no of days
 find $1/* -mtime -$3 -print >tmp/cpnew_files
 #===========================================
 #
 x=0;
 exec 3< tmp/cpnew_files    # open namesfile (using file descriptor #3)
 while read -u3 fp
 do
   let x=x+1
   fn=${fp##*/}                   # strip off left path to filename only
   echo "copy file# $x - $1/$fn "
   cp -p $1/$fn $2/$fn
   #==================
 done
 exec 3<&-           # close file descriptor #3
 echo "$x files (newer than $3 days) copied from $1 to $2"
 exit

Goto:   Begin this document End this document UVSI Home-Page

6D2. copying & sorting files from 1 dir to a 2nd dir

cpnew2 - copy files within a modification date range

 #!/bin/ksh
 # cpnew2 - Korn shell script from UVSI stored in: /home/uvadm/sf/util/
 # cpnew2 - copy files from 1 directory to a 2nd directory whose last
 #          modification times are within a specified date range
 #          specify dates as for the 'touch' command--> YYMMDDhhmm
 #
 #usage:  cpnew2 indir outdir YYMMDDhhmm1 YYMMDDhhmm2
 #        ===========================================
 #
 #example: cpnew2 dir1 dir2 9804010000 9804302359   copy April 98 files
 #         ======================================
 #
 if [[ (-d "$1") && (-d "$2") && (-n "$3") && (-n "$4") ]]; then :
 else echo "USAGE: cpnew2 indir outdir YYMMDDhhmm1 YYMMDDhhmm2 "; exit 1; fi
 #
 if (( (${#3} == 10) && (${#4} == 10) )); then :
 else echo "arg3 & arg4 must be 10 digits (YYMMDDhhmm)"; exit 2; fi
 #
 # create tmp dir in current dir if not already present
 if [[ ! -d tmp ]]; then mkdir tmp; fi
 #
 # create 2 files & use touch to set dates to the specified dates
 >tmp/cpnew2date1; >tmp/cpnew2date2
 touch -am -t $3 tmp/cpnew2date1
 touch -am -t $4 tmp/cpnew2date2
 #
 x=0; y=0;
 for f in $1/*
 do
   let x=x+1
   if [[ (-f $f) && ($f -nt tmp/cpnew2date1) && ($f -ot tmp/cpnew2date2) ]]
   then let y=y+1
        fn=${f##*/}                     # strip left to filename only
        echo "copy file# $x - $1/$fn "
        cp -p $1/$fn $2/$fn
        #==================
   fi
 done
 echo "$y files of $x total (dated $3 to $4) copied from $1 to $2"
 exit

Goto:   Begin this document End this document UVSI Home-Page

6E1. copying & sorting files from 1 dir to a 2nd dir

sortcpio - copy/sort all subdirs/files from dir1 to dir2

 #!/bin/ksh
 # sortcpio - Korn shell script from UVSI stored in: /home/uvadm/sf/adm/
 # sortcpio  - sort filenames & copy a directory to a 2nd directory
 #           - so filenames will be in sequence for backups, etc
 #             (ls sorts filenames, but not tar, cpio, du, etc)
 #           - input may have sub-directories to any level
 #           - output will have exactly the same tree structure
 #             except directory names & filenames will be sorted
 #
 if [[ -d $1 && -d $2 ]]; then :
    else echo "usage: sortcpio indir outdir"
         echo "       ====================="
         echo "- you must be outside of dirs & outdir must be empty"
         exit 1; fi
 #
 echo "current directory must be outside of indir & have tmp subdir - OK ?";read
 echo "outdir can be anywhere outside of indir & must be empty - OK ?";read
 #
 cwd=$(pwd)
 cd $1; d1=$(pwd); cd $cwd
 cd $2; d2=$(pwd); cd $cwd
 if [[ ! -d tmp ]];then mkdir tmp; fi
 cd $d1
 #
 find . -print >$cwd/tmp/files1
 #=============================
 sort -o$cwd/tmp/files2 $cwd/tmp/files1
 #=====================================
 cat $cwd/tmp/files2 | cpio -pdmv $d2
 #===================================
 exit 0

Goto:   Begin this document End this document UVSI Home-Page

6F1. copying & sorting files from 1 dir to a 2nd dir

sortall - sort all text files from dir1 to dir2

 #!/bin/ksh
 # sortall - sort all text files from 1 subdir to a 2nd subdir
 #         - maintaining same filenames in output directory
 #         - using unix/linux 'sort' utility vs 'uvsort' (sortallu1/u2)
 #
 if [[ -d "$1" && -d "$2" ]]; then :
    else echo "arg1 & arg2 must be subdirs"
         echo "usage: sortall indir outdir"
         echo "       ===================="
    exit 1; fi
 #
 d1=$1; d2=$2
 x=0
 for df in $d1/*
   { f=${df##*/}
     sort -o $d2/$f $d1/$f
     let x=x+1
   }
 echo "$x files sorted from $d1 to $d2"
 exit 0

Goto:   Begin this document End this document UVSI Home-Page

Part_7 Vancouver Utility scripts for Conversion & General use

system administration scripts

7A1. Notes about scripts requiring 'root' permissions

 7B1. killuser1 - kill user by username (vs process-ID)
                - saves having to search for process-ID via ps
 7B2. killuser2 - kill all users who forgot to logoff
                - run by cron at 3AM before processing console logs

7B3. crontab_root - used to schedule 'killuser2' at 3 AM

 7C1. chmod1 - change permissions on directories & files
             - using 'find' to process all levels of directories & files
             - need to manually add 'x' perms on any bin/* & script/* dirs
 7C2. chmod2 - change permissions on directories & files
             - using 'recursion' to process all levels of subdirs
             - need to manually add 'x' perms on any bin/* & script/* dirs
 7C3. chmod3 - change permissions on directories, files,& executable files
             - using 'recursion' to process all levels of subdirs
             - adds 'x' perms on any bin/* & script/* dirs, by testing
               for known names of bin & script subdirs
 7D1. ftrigger51 - script to test for a file presence & run a 2nd script
                 - use to run a JCL/script when a file is FTP'd to server
                 - simple version with hard-coded filename & jobname
 7D2. ftrigger52 - general purpose script test file presence & run 2nd script
                 - accepts arguments for filename & script to be run

Goto:   Begin this document End this document UVSI Home-Page

7A1. Notes about system/application administration scripts

  1. These scripts are also documented in ADMjobs.htm, along with other system administration scripts such as backup scripts & console log processing scripts.

  2. We should use 'root' only when absolutely necessary (as in killuser).

  3. The backup scripts (& most scripts ADMjobs.doc) do not need root, because they backup the application data & libraries (not the unix/linux system).

  4. The backup scripts are run by cron, but the crontab is not owned by root. The nightly 'crontabs' are owned by 'appsadm' which is in the same group as the programmers & operators, and has access to the data & libraries.

  5. Note that scripts run by 'cron' do not get the owner's profile executed automatically, so these scripts 1st '.' dot execute the profile (/home/appsadm/env/stub_profile). Then these scripts have all the usual environmental variables & PATHs setup to run the same as for console operation.

Goto:   Begin this document End this document UVSI Home-Page

7B1. system/application administration scripts

killuser1 - kill user by username (vs process#)

 #!/bin/ksh
 # killuser1 - Korn shell script from UVSI stored in: /home/uvadm/sf/adm/
 # killuser1 - kill any 1 user (must be run by root)
 #           - by Owen Townsend, www.uvsoftware.ca May 2002
 #           - also see killuser2 to kill all users running bash
 #             (killuser2 intended for cron at 3AM or whatever)
 #
 # verify arg1 specified
 user="$1"
 if [ -z "$user" ]; then
    echo "arg1 userid must be specified"
    echo "usage: killuser1 userid"
    echo "       ================"
    exit 1; fi
 #
 # redirect ps output to a tmp file
 # - use '-o' output option for 3 fields only (COMMAND, PID,& RUSER)
 ps -u $user -ocomm -opid -oruser >/tmp/kill$user
 #===============================================
 #    ** sample output lines **
 # COMMAND            PID RUSER
 # init                 1 root
 # bash              9022 root
 # bash              9077 uvadm
 # ps                9226 uvadm
 #
 # - open the file & read back into variables for easier manipulation
 exec 3< /tmp/kill$user        # open file #3
 #
 x=0; y=0
 while read -u3 comm pid ruser
 do if [[ ("$ruser" == "$user") && ("$comm" == "bash") ]]
       then let x=x+1
            kill -9 $pid
            #===========
            if [[ $? == 0 ]]; then kok=OK; let y=y+1; else kok=NAK; fi
            echo "#$x kill $comm $pid $ruser - $kok"
    fi
 done
 exec 3<&-                    # close file #3
 echo "$x kills attempted, $y killed OK $(date)"

Goto:   Begin this document End this document UVSI Home-Page

7B2. system/application administration scripts

killuser2 - kill all users who forgot to logoff

 #!/bin/ksh
 # killuser2 - Korn shell script from UVSI stored in: /home/uvadm/sf/adm/
 # killuser2 - kill users who did not logout
 #           - by Owen Townsend, www.uvsoftware.ca, March 2002
 #
 # - intended to be run by crontab_root at 11:45 PM or whenever
 # - killuser2 is run before logfixN which processes user console logs
 # - this kills user 'script' & closes the script output file
 # - also see 'killuser1' script for interactive use to kill any 1 user
 #
 if [ "$1" != "all" ]; then
    echo "usage: killuser2 all"
    echo "       ============="
    echo " - arg1 must be 'all'"
    exit 1; fi
 #
 # redirect ps -f output to a tmp file
 # - use '-o' output option for 3 fields only (COMMAND, PID,& RUSER)
 ps -e -ocomm -opid -oruser >/tmp/psef
 #====================================
 #    ** sample output lines **
 # COMMAND            PID RUSER
 # init                 1 root
 # bash              9022 root
 # bash              9077 uvadm
 # ps                9226 uvadm
 #
 # - open the file & read back into variables for easier manipulation
 exec 3< /tmp/psef            # open file #3
 #
 x=0; y=0
 while read -u3 comm pid ruser
 do if [[ ("$comm" == ksh || "$comm" == bash) && ("$ruser" != root) ]]
       then let x=x+1
            kill -9 $pid
            #===========
            if [[ $? == 0 ]]; then kok=OK; let y=y+1; else kok=NAK; fi
            echo "#$x kill $comm $pid $ruser - $kok"
    fi
 done
 exec 3<&-                    # close file #3
 echo "$x kills attempted, $y killed OK $(date)"

Goto:   Begin this document End this document UVSI Home-Page

7B3. system/application administration scripts

crontab_root - to schedule 'killuser2' at 3 AM

 # crontab_root - Korn shell script from UVSI stored in: /home/uvadm/sf/adm/
 # crontab_root - crontab file to run under root
 #
 # this file in: /home/appsadm/sf/crontab_root
 # - actual crontab for root depends on the unix/linux OS
 # - you need to find it & add desired lines
 # - OR, you could use the following procedure so you could maintain
 #   all crontabs in 1 place /home/appsadm/sf/...
 #   (after you have retrieved & combined root crontabs with this file)
 #
 # suggested procedures for updating root crontab:
 # 1. logon as root & cd to /home/appsadm
 # 2. crontab -l (if 1st setup)   - list to see if any crontab exists for root
 # 3. crontab -l >sf/crontab_root - ifso, redirect to sf/appsadm
 # 4. vi sf/crontab_root          - edit this file as required
 # 4a. :r /home/uvadm/sf/adm/crontab_root   <-- append this supplied file
 # 5. crontab -r                  - remove old crontab file for root
 # 6. crontab sf/crontab_root     - activate new crontab for root
 # 7. crontab -l                  - list crontab file to confirm installation
 #
 # minute hour day-of-mth mth-of-yr day-of-week <----command---->
 #
 55 02 * * * /home/appsadm/sf/killuser2 all
 #=========================================
 #
 # - killuser2 kills all 'ksh' users who did not log off
 # - also see killuser1 to interactively kill any 1 specified userid
 #   (without having to pre-determine the user's process#)
 #
 #-----------------------------------------------------------------
 # Note - original crontab lines for 'root' could appear here
 #      - or this file appended to end of unix/linux OS crontab
 #-----------------------------------------------------------------

Goto:   Begin this document End this document UVSI Home-Page

7C1. system/application administration scripts

chmod1 - set perms on all levels - using 'find'

 #!/bin/ksh
 # chmod1 - change permissions on subdirs & files under a specified superdir
 #        - using 'find' to process all levels of directories & files
 #        - need to manually add 'x' perms on any bin/* & script/* dirs
 #        - by Owen Townsend, April 26/2006
 #
 # chmod1 directory dir-perms file-perms   <-- command format
 # ======================================
 # chmod1 directory 775 664                <-- recommended permissions
 # =========================
 #
 # - also see alternatives chmod2 & chmod3 (to this *chmod1)
 #*chmod1 - change perms on dirs & files, using 'find'
 # chmod2 - change perms on dirs & files, using 'recursion'
 # chmod3 - change perms on dirs & files, using 'recursion'
 #        - sets 'x' perm by testing for known names of bin/ & script/ subdirs
 #
 # After running chmod1 or chmod2, you must manually fix permissions on
 # executable programs & scripts via -->chmod 775 bin/*; chmod 775 scripts/*
 #
 # capture arguments & force perms integers
 dir="$1";
 typeset i dperm="$2"; typeset i fperm="$3";
 #
 # ensure arg1 is directory & length of perms are 3 digits
 dpl=${#dperm}; fpl=${#fperm};
 #
 if [[ -d "$dir" ]] && ((dpl==3 && fpl==3)); then :
    else echo "usage: chmod1 directory dir-perms file-perms"
         echo "       ====================================="
         echo "example: chmod1 dirxx 775 664"
         echo "         ===================="
         echo " - arg1 must be dir, args 2 & 3 must be 3 digits"
         exit 90; fi
 #
 echo -n "chmod1: set perms $dperm/$fperm from: $dir - enter to continue"
 read reply
 #
 find $dir -type d -exec chmod $dperm {} \;
 #=========================================
 #
 find $dir -type f -exec chmod $fperm {} \;
 #=========================================
 #
 echo "chmod1: perms set $dperm/$fperm for all subdirs & files within: $dir"
 exit 0

Goto:   Begin this document End this document UVSI Home-Page

7C2. system/application administration scripts

chmod2 - set perms on all levels - using 'recursion'

 #!/bin/ksh
 # chmod2 - change permissions on subdirs & files under a specified superdir
 #         - using 'recursion' to process all levels of subdirs
 #         - need to manually add 'x' perms on any bin/* & script/* dirs
 #         - by Owen Townsend, June 13/2006
 #
 # chmod2 directory dir-perms file-perms    <-- command format
 # =====================================
 # chmod2 directory 775 664     <-- recommended permissions
 # ========================
 #
 # - also see alternatives chmod1 & chmod3 (to this *chmod2)
 # chmod1 - change perms on dirs & files, using 'find'
 #*chmod2 - change perms on dirs & files, using 'recursion'
 # chmod3 - change perms on dirs & files, using 'recursion'
 #        - sets 'x' perm by testing for known names of bin/ & script/ subdirs
 #
 # capture arguments & force perms integers
 dir="$1";
 typeset i dperm="$2"; typeset i fperm="$3";
 # ensure arg1 is directory & length of perms are 3 digits
 dpl=${#dperm}; fpl=${#fperm};
 if [[ -d "$dir" ]] && ((dpl==3 && fpl==3)); then :
    else echo "usage: chmod2 directory dir-perms file-perms"
         echo "       ====================================="
         echo "example: chmod2 dirxx 775 664"
         echo "         ===================="
         echo " - arg1 must be dir, args 2,3 must be 3 digits"
         exit 90; fi
 echo -n "chmod2: Begin directory $dir - enter to continue"
 read reply
 #note - remove the pause (read reply) above if desired
 integer nd=0 nf=0
 for df in $dir/*
   { if [[ -d $df ]]
        then chmod $dperm $df; ((nd+=1))
        else chmod $fperm $df; ((nf+=1))
     fi
     # if current entry in current dir is a subdir
     # - call this script again to process its files & subdirs
     # - using 'recursion' to process all existing levels of subdirs
     # - but do not call if directory is empty
     if [[ -d $df ]]; then
        ls $df >/tmp/chmod2
        if [[ -s /tmp/chmod2 ]]; then
           chmod2 $df $dperm $fperm
           #=======================
        fi
     fi
   }
 echo "chmod2: End dir $dir, subdirs=$nd, files=$nf"
 exit 0

Goto:   Begin this document End this document UVSI Home-Page

7C3. system/application administration scripts

chmod3 - set perms using recursion & add x to bin/script

 #!/bin/ksh
 # chmod3 - change permissions on subdirs & files under a specified superdir
 #        - using 'recursion' to process all levels of subdirs
 #        - adds 'x' perms on any bin/* & script/* dirs, by testing
 #          for known names of bin & script subdirs
 #        - by Owen Townsend, June 13/2006
 #
 # chmod3 directory dir-perms file-perms xfile-perms   <-- command format
 # ==================================================
 # chmod3 directory 775 664 775    <-- recommended permissions
 # =============================
 #
 # - also see alternatives chmod1 & chmod2 (to this *chmod3)
 # chmod1 - change perms on dirs & files, using 'find'
 # chmod2 - change perms on dirs & files, using 'recursion'
 #*chmod3 - change perms on dirs & files, using 'recursion'
 #        - sets 'x' perm by testing for known names of bin/ & script/ subdirs
 #
 # After running this script, you must manually fix permissions on executable
 # programs & scripts via -->chmod 775 bin/*; chmod 775 scripts/*
 # - if you can't modify the script to recognize all your bin & script dirs
 #
 # capture arguments & force perms integers
 dir="$1";
 typeset i dperm="$2"; typeset i fperm="$3"; typeset i xperm="$4";
 # ensure arg1 is directory & length of perms are 3 digits
 dpl=${#dperm}; fpl=${#fperm}; xpl=${#xperm};
 if [[ -d "$dir" ]] && ((dpl==3 && fpl==3 && xpl==3)); then :
    else echo "usage: chmod3 directory dir-perms file-perms xfile-perms"
         echo "       ================================================="
         echo "example: chmod3 dirxx 775 664 775"
         echo "         ========================"
         echo " - arg1 must be dir, args 2,3,4 must be 3 digits"
         exit 90; fi
 echo -n "chmod3: Begin directory $dir - enter to continue "
 read reply
 #note - remove the pause (read reply) above if desired
 integer nd=0 nf=0 nxf=0
 for df in $dir/*
   { if [[ -d $df ]] then chmod $dperm $df; ((nd+=1))
        elif [[ $df == *script* || $df == *sf* || $df == *bin*
                                               || $df == *program* ]]
             then chmod $xperm $df; ((nxf+=1))
        else chmod $fperm $df; ((nf+=1))
     fi
     # if current entry in current dir is a subdir
     # - call this script again to process its files & subdirs
     # - using 'recursion' to process all existing levels of subdirs
     # - but do not call if directory is empty
     if [[ -d $df ]]; then
        ls $df >/tmp/chmod3
        if [[ -s /tmp/chmod3 ]]; then
           chmod3 $df $dperm $fperm $xperm
           #==============================
        fi
     fi
   }
 echo "chmod3: End dir $dir, subdirs=$nd, files=$nf, xfiles=$nxf"
 exit 0

Goto:   Begin this document End this document UVSI Home-Page

7D1. system/application administration scripts

ftrigger51 - test file presence & run a script

 # ftrigger51 - script to test for a file presence & run a 2nd script
 #            - could use to run a JCL/script when a file is FTP'd to server
 #            - by Owen Townsend, March 30/2005
 #            - 2 versions of this script (ftrigger51 & ftrigger52)
 #*ftrigger51 - simple version with hard-coded filename & jobname
 #            - need to copy/rename/modify for other filenames & jobnames
 # ftrigger52 - general purpose version with 2 args for filename & jobname
 #
 jobset51;  # call setup function common to scripts converted from mainframe JCL
 #            - remove 'jobset51' for scripts unrelated to mainframe conversions
 # 'jobset51' - a Vancouver Utility function to setup the job environment
 #            - changes directory to $RUNDATA (with subdirs ftp, etc)
 #            - see MVSJCL.htm#1C3 explanation & listing at MVSJCL.htm#3C1
 #
 # assign variables for hard-coded file/job names up front in 1 place only
 # - to make script easier to copy/rename/modify for other filenames/jobnames
 file1="ftp/customer.master"     # hard-code filename here (1 place only)
 script1="jar160.ksh"            # hard-code jobname here (1 place only)
 #
 logmsg "$0 waiting for $file1 to run $script1"
 #
 # sleep 2 seconds repeatedly, until the arg1 file is detected
 until [[ -f $file1 ]]
    do sleep 2
    done
 #
 # file presence detected - run arg2 JCL/script & rename the file
 file2=${file1}_$(date +%y%m%d:%H%M%S)  # add _date:time stamp on filename
 #
 $script1        # run the JCL/script with no arguments (vs ftrigger52)
 #=======
 cc=$?           # capture return status
 if (($cc != 0))
    then logmsg "$script1 $file1 FAILED (return code $cc)"; exit $cc; fi
 #
 mv $file1 $file2   # rename the input file (so we can rerun this script)
 #
 logmsg "$script1 ran OK & $file1 renamed to $file2"
 exit 0

Goto:   Begin this document End this document UVSI Home-Page

7D1. system/application administration scripts

ftrigger52 - G.P. test file presence & run a script

 # ftrigger52 - script to test for a file presence & run a 2nd script
 #            - could use to run a JCL/script when a file is FTP'd to server
 #            - by Owen Townsend, March 30/2005
 #            - 2 versions of this script (ftrigger51 & ftrigger52)
 # ftrigger51 - simple version with hard-coded filename & jobname
 #            - would need to copy/rename/modify for other filenames & jobnames
 #*ftrigger52 - general purpose version with 2 args for filename/jobname
 #
 jobset51;  # call setup function common to scripts converted from mainframe JCL
 #            - remove 'jobset51' for scripts unrelated to mainframe conversions
 # 'jobset51' - a Vancouver Utility function to setup the job environment
 #            - changes directory to $RUNDATA (with subdirs ftp, etc)
 #            - see MVSJCL.htm#1C3 explanation & listing at MVSJCL.htm#3C1
 #
 if [[ -n "$1" && -n "$2" ]]; then :
 else echo "usage: ftrigger52 filename JCL/script  <-- 2 arguments must be coded"
      echo "       ============================="
      echo "example: ftrigger52 ftp/customer.master jar160.ksh"
      echo "         ========================================"
      exit 1; fi
 #
 file1=$1; script1=$2;   # name the variables
 logmsg "$0 waiting for $file1 to run $script1"
 #
 # sleep 2 seconds repeatedly, until the arg1 file is detected
 until [[ -f $file1 ]]
    do sleep 2
    done
 #
 # file presence detected - run arg2 JCL/script & rename the file
 file2=${file1}_$(date +%y%m%d:%H%M%S)  # add _date:time stamp on filename
 #
 $script1 $file1    # run the JCL/script with filename as arg1
 #==============
 cc=$?              # capture return status
 if (($cc != 0))
    then logmsg "$script1 $file1 FAILED (return code $cc)"; exit $cc; fi
 #
 mv $file1 $file2   # rename the input file (so we can rerun this script)
 #
 logmsg "$script1 ran OK & $file1 renamed to $file2"
 exit 0

Goto:   Begin this document End this document UVSI Home-Page

Visitor Counters for ThisYear and LastYear

ThisYear=000684   (J=135,F=129,M=170,A=151,M=99,J=0,J=0,A=0,S=0,O=0,N=0,D=0)
LastYear=001236   (J=78,F=75,M=122,A=91,M=99,J=111,J=95,A=99,S=113,O=121,N=116,D=116)