#!/bin/bash
DEBUG=0
E_OPTERROR=65
LogFile=/var/log/****/purgedir.log
Help( )
{
echo Example:
echo " `basename $0` -A ALL purge cache";
echo " `basename $0` -h : show help message";
echo " `basename $0` -v : show version";
exit $E_OPTERROR
}
Version( )
{
echo "
}
purgeCache()
{
local Dir=$1
echo "$(date "+%m-%d %H:%M:%S") $Dir is purged">> $LogFile
[ "$DEBUG" -ge "1" ] &&echo "In purgeDir purgeing $Dir"
N=1
Conf=/usr/local/squid/etc/squid.conf
pkill -9 squid 2>&1 1>> $LogFile
pkill -9 refreshd >/dev/null 2>&1
for x in $(awk '$1 ~ /^cache_dir/ {if ($3 ~ /.*\/$/) {print $3 "swap.state"} \
else {print $3 "/swap.state"}}' $Conf|xargs -n 1 echo)
do
echo '' > $x
done
[ -e "/data/refresh_db" ]&&rm -f /data/refresh_db/*
/etc/init.d/squid start 1>/dev/null #2>&1
Stat=$(/sbin/pidof '(squid)')
while [ -z "$Stat" ]
do
/etc/init.d/squid start 1>/dev/null #2>&1
Stat=$(/sbin/pidof '(squid)')
done
if [ -z "$Stat" ]
then
echo "HTTP/1.0 400 Bad Request"
else
echo "HTTP/1.0 200 OK"
/usr/local/squid/bin/refreshd -k url_verify
fi
#exit 0
}
funA()
{
#no delay,check the permission
local Arg=$1
[ "$DEBUG" -ge "1" ]&&echo "In funA: Arg=$Arg"
if [ "$Arg" = "ALL" ];then
purgeCache $Arg
else
echo "WARNING: Option ' -A $Arg' is invalidated!"
fi
}
opt=0
while getopts "VvhHA:" Option
do
case $Option in
A )
funA $OPTARG
opt=1
;;
v|V)
Version
opt=1
;;
h|H)
Help
opt=1
;;
* )
Help
opt=1
;;
esac
done
if [ $opt -eq 0 ]
then
Help
fi
exit 0
一个清除squid cache脚本
精选 转载上一篇:Tomcat VS JBoss
下一篇:squid不缓存指定url和网站
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
一个清除日志的脚本
#!/bin/bashLOG_DIR=/var/logROOT_UID=0LINES=50E_XCD=66E_NOTROOT=67
linux 职场 休闲 shell总结 -
清除指定squid缓存文件的脚本
(object)。squid会根据用户请求网页的URL进行哈希,生成缓存文件,
清除指定squid缓存文件的脚本 缓存文件 缓存 html -
清除buffer和cache
echo 1 > /proc/sys/vm/drop_caches
清除 buffer cache