1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326
|
#!/bin/csh -f
################### Start of $RCSfile: cartagehandler,v $ ##################
#
# $Source: /home/alb/afbackup/afbackup-3.3.6/RCS/cartagehandler,v $
# $Id: cartagehandler,v 1.1 2001/11/02 10:37:28 alb Exp alb $
# $Date: 2001/11/02 10:37:28 $
# $Author: alb $
#
#
####### description ################################################
#
#
#
####################################################################
if ($#argv != 3) then
echo "Usage: `basename $0` <cartridge-number> <#-times-full> <configfile>"
exit 2
endif
set configfile="$3"
set cartridge="$1"
set num_uses="$2"
set OSNAME=`uname -s|sed 's/[^a-zA-Z]//g'`
alias gosub 'set stack=(\!:3 $stack); set __args=(\!:2) ; goto \!:1'
alias return 'set __lab=$stack[1] ; set stack=($stack[2-]) ; goto $__lab'
alias matches 'echo \!:1 |egrep -i \!:2|wc -l'
set stack=()
if (! $?BACKUP_HOME) then
set p=$0
set pnam=$p
set pnam=$pnam:t
if ($pnam == $0) then
foreach dir ($path)
if (-x $dir/$pnam) then
set p=$dir/$pnam
break
endif
end
endif
if (`echo $p|cut -c1` != "/") then
set p=`pwd`/$p
endif
set oldpath=$p
restart_resolv:
set newpath="$oldpath"_
while ("$newpath" != "$oldpath")
set newpath="$oldpath"
set oldpath=`echo "$oldpath"|sed 's#/\./#/#g;s#/\.$##g;s#//*#/#g;s#^\./##g;s#^/\.\./#/#g'`
if ("$oldpath" != '/') then
set oldpath=`echo "$oldpath"|sed 's#/*$##g'`
endif
end
if (`echo "$oldpath"|cut -c1` == "/") then
set oldhead="/"`echo "$oldpath"|cut -c2-|sed 's#/.*$##g'`
set oldtail=`echo "$oldpath"|cut -c2-|sed 's#^[^/]*/##'`
else
set oldhead=`echo "$oldpath"|sed 's#/.*$##g'`
set oldtail=`echo "$oldpath"|sed 's#^[^/]*/##'`
endif
if ("$oldpath" == "$oldhead") set oldtail=""
while (1)
if ("$oldhead" == "") set oldhead="."
if (! -f "$oldhead" && ! -d "$oldhead") then
set newpath=""
goto getout_1
endif
set linkchar=`ls -ld "$oldhead"|cut -c1`
if ($linkchar == 'l') then
set points_to=`ls -ld "$oldhead"|sed 's#^.*->[ ]*##g'`
if (`echo "$points_to"|cut -c1` == '/') then
set newpath="$points_to"/"$oldtail"
else
set newpath=`dirname "$oldhead"`/"$points_to"/"$oldtail"
endif
set oldpath="$newpath"
goto restart_resolv
endif
if ("$oldtail" == "") then
set oldpath="$oldhead"
break
endif
set oldhead="$oldhead"/`echo "$oldtail"|sed 's#/.*$##g'`
if (`echo "$oldtail"|grep /|wc -l` < 1) then
set oldtail=''
else
set oldtail=`echo "$oldtail"|sed 's#^[^/]*/##g'`
endif
end
set newpath="$oldpath"_
while ("$newpath" != "$oldpath")
set newpath="$oldpath"
set oldpath=`echo $oldpath|sed 's#[^/][^/]*/\.\./##g;s#[^/][^/]*/\.\.$##g;s#/\./#/#g;s#/\.$##g;s#//*#/#g;s#^\./##g;s#^/\.\./#/#g'`
if ("$oldpath" != '/') then
set oldpath=`echo "$oldpath"|sed 's#/*$##g'`
endif
end
getout_1:
set p="$newpath"
set p=$p:h
set bindir="$p"
set sbindir="$p"
setenv BACKUP_HOME "$bindir"
if ($BACKUP_HOME:t == "bin" || $BACKUP_HOME:t == "sbin") then
setenv BACKUP_HOME $BACKUP_HOME:h
endif
endif
if (! $?bindir) then
set bindir="$BACKUP_HOME/bin"
endif
if (! $?sbindir) then
set sbindir="$BACKUP_HOME/sbin"
endif
set NUMSET="$bindir"/__numset
if ( ! -x $NUMSET ) then
set NUMSET="$sbindir"/__numset
if ( ! -x $NUMSET ) then
echo "Error: No executable __numset found. Installation corrupt."
endif
endif
set path=($bindir $sbindir $path)
rehash
unsetenv AWK
# the solaris awk is doin' dawn f...... BS
foreach awk (nawk gawk awk)
foreach dir ($path)
if (-x $dir/$awk) then
setenv AWK $dir/$awk
break
endif
end
if ($?AWK) break
end
if (! $?AWK) then
echo 'No awk ? Is this really one of the wonderful UNIX-es ?'
echo 'Sorry. I have to exit.'
exit 1
endif
if (! -r $configfile) then
echo "Error: Cannot read configuration file $configfile. Exiting."
exit 3
endif
if (! -x $NUMSET) then
echo "Error: $NUMSET is not executable. Exiting"
exit 4
endif
alias getparam $AWK' '"'"'/^[ ]*'"'"'\!:1'"'"'/{sub("'"'"'\!:1'"'"'[ ]*",""); print}'"' $configfile"
set cartsetpat='[Cc]artr?i?d?g?e?[-_ ]*[Ss]ets:?'
set numcartspat='[Nn]umb?e?r?[-_ ]*[Oo]f[-_ ]*[Cc]artr?i?d?g?e?s[-_ ]*:?'
set usertoinformpat='[Uu]ser[-_ ]*[Tt]o[-_ ]*[Ii]nfor?m?:?'
set mailprogpat='[Mm]ail[-_ ]*[Pp]rogram:?'
set cartsets=(`getparam "$cartsetpat"`)
set numcarts=(`getparam "$numcartspat"`)
set usertoinform=(`getparam "$usertoinformpat"`)
set mailprog=(`getparam "$mailprogpat"`)
set mailprog=`echo $mailprog | sed 's/%u/'"$usertoinform/g"`
#
# User configured section
#
# The number of cartridge sets to operate on
set num_cartsets=3
#
# End User configured section
#
# Default, if no cartridge sets configured
if ($#cartsets == 0) then
set cartsets="1-$numcarts"
endif
# Fill up array to make the csh happy
while ($#cartsets < $num_cartsets)
set cartsets=($cartsets "")
end
#
# User implementable section
#
# available variables:
# num_cartsets: user configured above, the number of cartridge sets to modify
# cartsets(): array of cartridge set specifiers from config file
# cartridge: number of the current cartridge
# num_uses: times of the current cartridge having become full
# usertoinform: user to inform, if sth. goes wrong (from config file)
# mailprog: mail program from config file (with %u substituted)
#
# Useful: the program $NUMSET (see docs)
#
# decide to which set to move the cartridge
#
set settomoveto=1
if ($num_uses > 80) then
set settomoveto=2
if ($num_uses > 90) then
set settomoveto=3
if ($num_uses > 95) then
set settomoveto=0
endif
endif
endif
#
# check, in which set the cartridge currently is
#
set actset=1 # (dummy)
set i=1
while ($i <= $num_cartsets)
set modset=`$NUMSET "$cartsets[$i]" - "$cartridge"`
if ("$modset" != "$cartsets[$i]") then
# Changed: number is in this set
set actset=$i
break
endif
@ i++
end
#
# If the cartridge is already in a set equal to or higher than
# the target set and a target set has been determined, there is
# nothing to do (cartridges can only move "up")
#
if ($actset >= $settomoveto && $settomoveto > 0) then
exit 0
endif
#
# remove cartridge from current set
#
# in two steps cause of C-shell bug workaround
set cs=`$NUMSET "$cartsets[$actset]" - "$cartridge"`
#
# Check, if set became empty, what would lead to an error
#
if ("$cs" == "") then
set targetsetname="$settomoveto"
if ($targetsetname < 1) set targetsetname='"outdated"'
(eval "cut -c5- | $mailprog") << ENDOFMAIL
> Hello,
>
> this is your program moving cartridges to other cartridge
> sets, when their number of uses exceeds certain limits.
> The cartridge $cartridge has $num_uses uses now, it should be moved
> to set $targetsetname.
> The problem is, that set $actset would then become empty.
> Therefore cartridge $cartridge remains in set $actset. Please provide
> more cartridges for set $actset and update the configuration
> file $configfile properly.
>
> Kind regards,
>
> Your automatic cartridge age handler
>
ENDOFMAIL
exit 0
endif
set cartsets[$actset]=$cs
if ($settomoveto > 0) then
set cs=`$NUMSET "$cartsets[$settomoveto]" + "$cartridge"`
set cartsets[$settomoveto]=$cs
endif
#
# End User implementable section
#
set EST=0
set TMPFILE="$configfile".tmp.$$
onintr cleanup
/bin/rm -f $TMPFILE
if ( -e $TMPFILE) then
EST=1
goto cleanup
endif
/bin/cp -p $configfile $TMPFILE
$AWK '{if($0 ~ "^[ ]*'"$cartsetpat"'") sub("^[ ]*'"$cartsetpat"'.*$","Cartridge-Sets: '"$cartsets"'"); print}' $TMPFILE >! $configfile
cleanup:
/bin/rm -f $TMPFILE
exit $EST
|