home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.ee.lbl.gov
/
2014.05.ftp.ee.lbl.gov.tar
/
ftp.ee.lbl.gov
/
acld-1.11.tar.gz
/
acld-1.11.tar
/
acld-1.11
/
aclcompact.sh.in
< prev
next >
Wrap
Text File
|
2011-05-25
|
2KB
|
137 lines
#! /bin/sh
# @(#) $Id: aclcompact.sh.in 742 2011-05-26 01:05:15Z leres $ (LBL)
PATH="@PREFIX@/libexec:@PREFIX@/sbin:@PREFIX@/bin:${PATH}"
export PATH
prog="`basename $0`"
xstatus=0
comment="${prog}"
prog="`basename $0`"
t1="/tmp/${prog}.1.$$"
t2="/tmp/${prog}.2.$$"
. /etc/rc.conf
ACLCOMPACTPCT="${aclcompact_pct:-50}"
export ACLCOMPACTPCT
trap 'rm -f ${t1} ${t2}; exit 2' 1 2 3 15
if [ -f ${t1} ]; then
echo "${prog}: ${t1} already exists" 1>&2
exit 1
fi
acl.exp state -c "${comment}" > ${t1} 2>&1
xstatus=$?
if [ ${xstatus} -ne 0 ]; then
echo "${prog}: acld state failed" 1>&2
cat ${t1}
rm ${t1}
exit 1
fi
awk 'BEGIN {
highseq = -1
incrseq = 1
pct = ENVIRON["ACLCOMPACTPCT"]
}
/^# lastseq for ACL/ {
lastseq[$5] = $7
next
}
$1 == "seqrange" {
# legacy
lowseq = $2
highseq = $3
next
}
$1 == "lowseq" {
# legacy
lowseq = $2
next
}
$1 == "highseq" {
# legacy
highseq = $2
next
}
$1 == "incrseq" {
incrseq = $2
next
}
END {
if (pct <= 0) {
print "# ACLCOMPACTPCT not set"
exit 1
}
if (lowseq <= 0) {
print "# lowseq not set"
exit 1
}
if (highseq <= 0) {
print "# highseq not set"
exit 1
}
if (incrseq != 1) {
printf "# cannot handle incrseq %d\n", incrseq
exit 1
}
#printf "# pct %d\n", pct
#printf "# lowseq %d\n", lowseq
#printf "# highseq %d\n", highseq
#printf "# incrseq %d\n", incrseq
for (acl in lastseq) {
#printf "# acl %s %d\n", acl, lastseq[acl]
range = highseq - lowseq
if (range <= 0)
range = 1
used = int(((lastseq[acl] - lowseq) / range) * 100)
left = highseq - lastseq[acl]
#printf "# %s %d left\n", acl, left
if (used >= pct)
printf "compact %s -c \"(%d%% %d left)\"\n", acl, used, left
}
}' < ${t1} > ${t2} 2>&1
xstatus=$?
if [ ${xstatus} -ne 0 ]; then
echo "${prog}: awk script failed" 1>&2
cat ${t1}
echo "-----"
cat ${t2}
rm ${t1} ${t2}
exit 1
fi
if [ ! -s ${t2} ]; then
rm ${t1} ${t2}
exit 0
fi
command="`cat ${t2}`"
case "${command}" in
compact*)
acl.exp ${command} > ${t1} 2>&1
xstatus=$?
if [ ${xstatus} -ne 0 ]; then
echo "${prog}: acl.exp script failed" 1>&2
echo "# ${command}"
cat ${t1}
rm ${t1} ${t2}
exit 1
fi
;;
*)
exit 1
;;
esac
rm ${t1} ${t2}
exit 0