#!/bin/ksh # hpsstar script modified from 10/28/2011 version of hpsstar in /nwprod/util/ush/hpsstar # This script modifies hpss names that include /hpssuser as follows # FOR READS and QUERIES # For names that begin with /hpssuser, /NCEPDEV is prepended to the name. # If the name does not exist, the old /hpssuser name is retained. # For names that begin with /NCEPDEV/hpssuser, the name is checked for hpss existence # if it does not exist the /NCEPDEV prefix is removed and the script acts on that new stripped name. # # For WRITES AND DELETES , NO CHANGE TO NAMES IS MADE # THE SCRIPT WILL NEED MODIFICATION ON JANUARY 17, 2011 TO FORCE ALL /hpssuser WRITES AND DELETES # TO THE PREPENDED /NCEPDEV/hpssuser NAME ###******* RESTATEMENT OF ABOVE IN DOCUMENTATION BELOW ************** # PREFIX POLICY. ## ANY NAME THAT DOES NOT BEGIN WITH /hpssuser or /NCEPDEV is unaltered ## 1. /hpssuser names ## Any name that begins with /hpssuser will have /NCEPDEV ##added to it for READS and QUERIES. If the /NCEPDEV ##name does not exist, the old name will be used ## PRIOR TO JANUARY 17, 2012, WRITES and DELETES are unchanged. On Janury 17,2012 # ALL WRITES AND DELETES WILL HAVE THE PATH /NCEPDEV prepended to any name that begins with /hpssuser ## 2. /NCEPDEV names ## ANY NAME THAT BEGINS WITH /NCEPDEV WILL BE PROCESSED AS FOLLOWS ## FOR WRITES AND DELETES , NO CHANGE ## FOR READS and QUERIES, the /NCEPDEV NAME WILL BE CHECKED FIRST. IF IT DOES NOT EXIST the /NCEPDEV ## STRING WILL BE stripped AND THE NAME RECHECKED. ###******* END RESTATEMENT ## FUNCTIONS TO ADD/CUT NEW PREFIX TO /HPSSUSER tobjexist() { ntt=`echo $object | cut -c 1-8` if [ $ntt == '/NCEPDEV' ] then hsi -P ls -ld $object >/dev/null NRCC=$? ott=`echo $object | sed "s?/NCEPDEV/?/?" ` export old_hpss_pathname=$ott export new_hpss_pathname=$object hsi ls -ld $ott RCC=$? if [ $RCC -ne 0 ] then export oexistt=nope else export oexistt=yes fi if [ $NRCC -ne 0 ] then export nexistt=nope else export nexistt=yes fi else hsi ls -ld $object RCC=$? export old_hpss_pathname=$object export new_hpss_pathname=/NCEPDEV$object hsi -P ls -ld /NCEPDEV$object >/dev/null NRCC=$? if [ $RCC -ne 0 ] then export oexistt=nope else export oexistt=yes fi if [ $NRCC -ne 0 ] then export nexistt=nope else export nexistt=yes fi fi #ENDIF [ $ntt == '/NCEPDEV' ] } tobjadd() # ALWAYS prefix /NCEPDEV to any /hpssuser path # use for new writes a { if [[ "$VERBOSE_HPSSTAR" == yes ]] ; then set -x fi ott=`echo $object | cut -c 1-9` if [ $ott == '/hpssuser' ] then ott=/NCEPDEV"$object" if [ $VERBOSE_HPSSTAR == yes ] ; then echo APPENDED PATH $ott ; fi object=$ott else if [ $VERBOSE_HPSSTAR == yes ] ; then echo UNCHANGED PATH $object NOT PREPENDED ; fi fi } tobjaddif() # prefix /NCEPDEV to any /hpssuser path if NEW PATH exists # use for new reads { if [[ "$VERBOSE_HPSSTAR" == yes ]] ; then set -x fi ott=`echo $object | cut -c 1-9` if [ $nexistt -eq 'yes' ] then if [ $ott == '/hpssuser' ] then ott=/NCEPDEV"$object" if [ $VERBOSE_HPSSTAR == yes ] ; then echo APPENDED PRECHECKED PATH $ott ; fi object=$ott else if [ $VERBOSE_HPSSTAR == yes ] ; then echo UNCHANGED PATH $object ; fi fi else if [ $VERBOSE_HPSSTAR == yes ] ; then echo ADVISORY /NCEPDEV$object does not exist ; echo ADVISORY $object WILL BE RETAINED AS THE OBJECT ; fi fi } tobjcut() #ALWAYS STRIP /NCEPDEV FROM PATH IF IT IS IN THE PATH BEGINNING { if [[ "$VERBOSE_HPSSTAR" == yes ]] ; then set -x fi ott=`echo $object | cut -c 1-17` if [ $ott == '/NCEPDEV/hpssuser' ] then ott=`echo $object | sed "s?/NCEPDEV/?/?" ` if [ $VERBOSE_HPSSTAR == yes ] ; then echo STRIPPED PATH $ott ; fi object=$ott else if [ $VERBOSE_HPSSTAR == yes ] ; then echo UNCHANGED PATH $object NOT CUT ; fi fi } tobjcutif() #CONDITIONALLY STRIP /NCEPDEV FROM PATH IF IT IS IN THE PATH BEGINNING and # THE OBJECT DOES NOT EXIST { if [[ "$VERBOSE_HPSSTAR" == yes ]] ; then set -x fi ott=`echo $object | cut -c 1-17` if [ $ott == '/NCEPDEV/hpssuser' ] then if [ $nexistt != 'yes' ] then ott=`echo $object | sed "s?/NCEPDEV/?/?" ` if [ $VERBOSE_HPSSTAR == yes ] ; then echo STRIP /NCEPDEV FROM $ott ; fi object=$ott else if [ $VERBOSE_HPSSTAR == yes ] ; then echo EXISTING $object NOT CUT ; fi fi else if [ $VERBOSE_HPSSTAR == yes ] ; then echo PATH $object DOES NOT BEGIN WITH NCEPDEV, NOT CUT ; fi fi } ## HPSSTAR LOGIC BEGINS HERE # toggle path redirect information on or off (off unless "yes" in environment) if test $VERBOSE_HPSSTAR then break else VERBOSE_HPSSTAR=no fi if [[ "$VERBOSE_HPSSTAR" == yes ]] ; then set -x fi HSI="/apps/hpss/hsi" HTAR="/apps/hpss/htar" set -u usage="\ Usage: $0 man $0 quo [Userid|'all'|'alls#'] $0 put|pu1|pu2|putv Tarfile File ... $0 get|gem Tarfile [File ...] $0 getnostage|gemnostage Tarfile [File ...] $0 inv|inx|inw Tarfile $0 idx Tarfile $0 del|dem Tarfiles (wildcards accepted) $0 rmf|rmd Non-empty|empty Directory $0 ren Old-Dir-Name New-Name $0 dip|dir|dix [Tarfile|Directory] $0 mkd Directory $0 fnd Files/Directories (wildcards accepted) use 'hpsstar man' for detailed info" uhelp=' This script creates, retrieves, and manages tarfiles on HPSS. Actions: man prints this man page quo prints quota for you or another user or all or all sorted by field # put creates a tarfile (one copy) and its index pu1 creates a tarfile (one copy) and its index pu2 creates a tarfile (two copies) and its index get retrieves all or part of a tarfile gem retrieves all or part of a tarfile and redates the files getnostage better performance for retrieving part of a large tarfile gemnostage rbetter performance for retrieving part of a large tarfile and redates the files inv gives a verbose inventory of a tarfile inx gives just a list of entries in a tarfile inw gives a Wesley inventory of a tarfile idx rebuilds an index del deletes tarfiles and its index (wildcards accepted) dem deletes files with interactive response (wildcards accepted) rmf removes non-empty directories rmd removes empty directories ren rename directory dip gives a listing of a tarfile and its index dir gives a verbose listing dix gives a compact listing mkd makes a directory fnd traverse a directory tree looking for files and directories (wildcard accepted) Note that the default local directory is your own directory in /hpssuser; otherwise a full path name is required. This command interfaces with the High Performance Storage System (HPSS) using $HTAR and the client API. Class of Service is automatically computed. Examples. Check quota. hpsstar quo Make a directory. hpsstar mkd tmpdir Create a tarfile. hpsstar put tmpdir/Test.tar * Get a directory listing. hpsstar dir tmpdir Inventory a tarfile. hpsstar inv tmpdir/Test.tar Retrieve entire tarfile. hpsstar get tmpdir/Test.tar Retrieve just the .f files in a tarfile. hpsstar get tmpdir/Test.tar $(hpsstar inx tmpdir/Test.tar|grep '\''\.f$'\'') Using "nostage" option for better performance when retrieving small port of files in a large tarfile (>10GB) hpsstar getnostage tmpdir/Test.tar $(hpsstar inx tmpdir/Test.tar|grep '\''\.f$'\'') Delete all tarfiles beginning with T under tmpdir. for f in $(hpsstar dix tmpdir|grep ^T.*\.tar$);do hpsstar del tmpdir/$f;done or simply hpsstar del tmpdir/"T*.tar" Delete interactively all tarfiles beginning with T under tmpdir. hpsstar dem tmpdir/"T*.tar" Find all files begnning with T in the current directory tree hpsstar fnd "T*.tar" Remove a directory. hpsstar rmd tmpdir Rename a directory hpsstar ren olddir newdir For a large tarball (> ) and only extract a small port of files Mark Iredell Doris Pan April, 24, 2008' if [[ $# -eq 0 ]];then echo "$usage" >&2 exit 1 fi # # Check/set environment variables # rc=0 action=$1 object=${2:-.} tobjexist #echo ' EXIST ---- >>>> old = ' $oexistt ' new = ' $nexistt ' <<------' if [ $VERBOSE_HPSSTAR == yes ] then echo echo ' --- > 'OLD PATH $old_hpss_pathname $oexistt ' <<------' echo ' --- > ' NEW PATH $new_hpss_pathname $nexistt ' <<------' echo fi [[ $object = /* ]]||object=/home/$LOGNAME/$object case $action in man) echo "$usage";echo "$uhelp";; quo) object=${2:-$LOGNAME} if [[ $object = alls? ]];then hpssquota all|grep [A-Z] hpssquota all|grep -v [A-Z]|sort -nr -k${object#alls} else hpssquota $object;fi;; put) if [[ $# -ge 3 ]];then shift 2 tobjadd ; if [ $VERBOSE_HPSSTAR == yes ] ; then echo $object ' <--- FINAL OBJECT USED IN HPSSTAR ' ; fi t=0;for k in $(du -ks $*|awk '{print $1}');do ((t+=k));done;((t=t/1024)) if [[ $t -lt 30 ]];then c1=231;elif [[ $t -lt 2000 ]];then c1=231;else c1=231;fi t=$(ls -R $*|wc -l);((t=t/1024)) if [[ $t -lt 1 ]];then c2=3;elif [[ $t -lt 30 ]];then c2=3;else c2=3;fi $HTAR -T 5 -cvf $object $*;rc=$? else rc=-42;fi;; pu1) if [[ $# -ge 3 ]];then shift 2 tobjadd ; if [ $VERBOSE_HPSSTAR == yes ] ; then echo $object ' <--- FINAL OBJECT USED IN HPSSTAR ' ; fi t=0;for k in $(du -ks $*|awk '{print $1}');do ((t+=k));done;((t=t/1024)) if [[ $t -lt 30 ]];then c1=231;elif [[ $t -lt 2000 ]];then c1=231;else c1=231;fi t=$(ls -R $*|wc -l);((t=t/1024)) if [[ $t -lt 1 ]];then c2=3;elif [[ $t -lt 30 ]];then c2=3;else c2=3;fi $HTAR -T 5 -cvf $object $*;rc=$? else rc=-42;fi;; pu2) if [[ $# -ge 3 ]];then shift 2 tobjadd ; if [ $VERBOSE_HPSSTAR == yes ] ; then echo $object ' <--- FINAL OBJECT USED IN HPSSTAR ' ; fi t=0;for k in $(du -ks $*|awk '{print $1}');do ((t+=k));done;((t=t/1024)) if [[ $t -lt 30 ]];then c1=231;elif [[ $t -lt 2000 ]];then c1=231;else c1=231;fi t=$(ls -R $*|wc -l);((t=t/1024)) if [[ $t -lt 1 ]];then c2=3;elif [[ $t -lt 30 ]];then c2=3;else c2=3;fi $HTAR -T 5 -cvf $object $*;rc=$? else rc=-42;fi;; putv) if [[ $# -ge 3 ]];then shift 2 tobjadd ; if [ $VERBOSE_HPSSTAR == yes ] ; then echo $object ' <--- FINAL OBJECT USED IN HPSSTAR ' ; fi t=0;for k in $(du -ks $*|awk '{print $1}');do ((t+=k));done;((t=t/1024)) if [[ $t -lt 30 ]];then c1=231;elif [[ $t -lt 2000 ]];then c1=231;else c1=231;fi t=$(ls -R $*|wc -l);((t=t/1024)) if [[ $t -lt 1 ]];then c2=3;elif [[ $t -lt 30 ]];then c2=3;else c2=3;fi $HTAR -T 5 -H verify=compare -cvf $object $*;rc=$? else rc=-42;fi;; get) if [[ $# -ge 2 ]];then shift 2 tobjadd if [ $VERBOSE_HPSSTAR == yes ] ; then echo $object ADD ; fi tobjcutif if [ $VERBOSE_HPSSTAR == yes ] ; then echo $object ' <--- FINAL OBJECT USED IN HPSSTAR ' ; fi if [[ $# -eq 0 ]];then $HTAR -T 5 -xvf $object;rc=$? else $HTAR -T 5 -xvf $object $*;rc=$? fi else rc=-42;fi;; getnostage) if [[ $# -ge 2 ]];then shift 2 tobjadd ; if [ $VERBOSE_HPSSTAR == yes ] ; then echo $object ADD ; fi tobjcutif if [ $VERBOSE_HPSSTAR == yes ] ; then echo $object ' <--- FINAL OBJECT USED IN HPSSTAR ' ; fi if [[ $# -eq 0 ]];then $HTAR -T 5 -Hnostage -xvf $object;rc=$? else $HTAR -T 5 -Hnostage -xvf $object $*;rc=$? fi else rc=-42;fi;; gem) if [[ $# -ge 2 ]];then shift 2 tobjadd ; if [ $VERBOSE_HPSSTAR == yes ] ; then echo $object ADD ; fi tobjcutif if [ $VERBOSE_HPSSTAR == yes ] ; then echo $object ' <--- FINAL OBJECT USED IN HPSSTAR ' ; fi if [[ $# -eq 0 ]];then $HTAR -T 5 -xvmf $object;rc=$? else $HTAR -T 5 -xvmf $object $*;rc=$? fi else rc=-42;fi;; gemnostage) if [[ $# -ge 2 ]];then shift 2 tobjadd ; if [ $VERBOSE_HPSSTAR == yes ] ; then echo $object ADD ; fi tobjcutif echo $object ' <--- FINAL OBJECT USED IN HPSSTAR ' if [[ $# -eq 0 ]];then $HTAR -T 5 -Hnostage -xvmf $object;rc=$? else $HTAR -T 5 -Hnostage -xvmf $object $*;rc=$? fi else rc=-42;fi;; inv) if [[ $# -eq 2 ]];then tobjadd ; if [ $VERBOSE_HPSSTAR == yes ] ; then echo $object ADD ; fi tobjcutif if [ $VERBOSE_HPSSTAR == yes ] ; then echo $object ' <--- FINAL OBJECT USED IN HPSSTAR ' ; fi $HTAR -T 5 -tvf $object;rc=$? else rc=-42;fi;; inx) if [[ $# -eq 2 ]];then tobjadd tobjadd ; if [ $VERBOSE_HPSSTAR == yes ] ; then echo $object ADD ; fi tobjcutif if [ $VERBOSE_HPSSTAR == yes ] ; then echo $object ' <--- FINAL OBJECT USED IN HPSSTAR ' ; fi $HTAR -T 5 -tvf $object|awk '{print $7}';rc=$? else rc=-42;fi;; inw) if [[ $# -eq 2 ]];then tobjadd ; if [ $VERBOSE_HPSSTAR == yes ] ; then echo $object ADD ; fi tobjcutif if [ $VERBOSE_HPSSTAR == yes ] ; then echo $object ' <--- FINAL OBJECT USED IN HPSSTAR ' ; fi echo $object $($HTAR -T 5 -tvf $object|awk '{print $7}'|tr '\n' ' ');rc=$? else rc=-42;fi;; idx) if [[ $# -eq 2 ]];then tobjadd ; if [ $VERBOSE_HPSSTAR == yes ] ; then echo $object ADD ; fi tobjcutif if [ $VERBOSE_HPSSTAR == yes ] ; then echo $object ' <--- FINAL OBJECT USED IN HPSSTAR ' ; fi $HSI "rm $object.idx" t=$($HTAR -T 5 -Xvf $object |wc -l);((t=t/1024)) if [[ $t -lt 1 ]];then c2=3;elif [[ $t -lt 30 ]];then c2=3;else c2=3;fi $HSI "rm $object.idx" $HTAR -T 5 -Xvf $object ;rc=$? else rc=-42;fi;; del) if [[ $# -eq 2 ]];then $HSI "rm $object; rm $object.idx"; rc=$? else rc=-42;fi;; dem) if [[ $# -eq 2 ]];then $HSI "mdelete $object; mdelete $object.idx"; rc=$? else rc=-42;fi;; rmf) if [[ $# -eq 2 ]];then $HSI "rm -R $object/*; rmdir $object";rc=$? else rc=-42;fi;; rmd) if [[ $# -eq 2 ]];then $HSI "rmdir $object";rc=$? else rc=-42;fi;; ren) if [[ $# -ge 3 ]];then shift 2 if [[ $# -eq 1 ]];then $HSI "rename $object $*";rc=$? fi else rc=-42;fi;; dip) if [[ $# -le 2 ]];then $HSI -P "ls -l $object"; rc=$?;[[ $rc = 0 ]]&&$HSI -P "ls -l $object.idx" else rc=-42;fi;; dir) if [[ $# -le 2 ]];then $HSI -P "ls -l $object";rc=$? else rc=-42;fi;; dix) if [[ $# -eq 2 ]];then $HSI list $object;rc=$?; elif [[ $# -eq 1 ]]; then $HSI list ;rc=$? else rc=-42;fi;; mkd) if [[ $# -eq 2 ]];then $HSI mkdir -p $object;rc=$? else rc=-42;fi;; fnd) if [[ $# -eq 2 ]];then object=${2:-$object} echo $object $HSI find . -name $object -depth -print rc=$? else rc=-42;fi;; *) rc=-41;; esac if [[ $rc -eq -41 ]];then echo $0: unrecognized action $action >&2 echo "$usage" >&2 elif [[ $rc -eq -42 ]];then echo $0: incorrect number of arguments for action $action >&2 echo "$usage" >&2 fi exit $rc #######################