admin 管理员组文章数量: 1086019
2024年3月30日发(作者:mavenrepository是自动生成的吗)
echo " "
echo "SYNOPSIS"
echo " "
echo "DESCRIPTION"
echo " clear the server logs and temp files"
exit 0
}
function writelog()
{
local logfile=$1
local debug_level=$2
local messages=$3
echo "[$(date '+%Y-%m-%d %H:%M:%S')] [${debug_level}] ${messages}"
echo "[$(date '+%Y-%m-%d %H:%M:%S')] [${debug_level}] ${messages}" >> ${logfile}
}
function find_logs()
{
local user=$1
local user_home=$2
if [ -d ${user_home}/log ];then
find ${user_home}/log -maxdepth 2 -type f -name "${user}*.log*" -mtime +${KEEP_DAYS} -print >> "${DELETE_LOGS_LIST}"
fi
if [ -d ${user_home}/temp ];then
find ${user_home}/temp -maxdepth 2 -type f -name "${user}*.tmp*" -mtime +${KEEP_DAYS} -print >> "${DELETE_LOGS_LIST}"
fi
}
if [ "X$1" == "X--help" ];then
Usage
fi
if [ $(whoami) != 'root' ];then
printf "Please use root to executen"
exit 1
fi
##global Var
CURRENT_PATH=$(pwd)
CURRENT_DATE=$(date '+%Y%m%d')
SCRIPT_NAME="clearlogs"
CLEARLOGS_DIR="${CURRENT_PATH}/${SCRIPT_NAME}_${CURRENT_DATE}"
SEARCH_FILE_SIZE='100M'
LOG_FILE="${CLEARLOGS_DIR}/${SCRIPT_NAME}.log"
DELETE_LOGS_LIST="${CLEARLOGS_DIR}/${SCRIPT_NAME}_delete_"
USER_LIST="${CLEARLOGS_DIR}/"
BIG_FILES_LIST="${CLEARLOGS_DIR}/${SCRIPT_NAME}_"
KEEP_DAYS=3
if [ ! -d ${CLEARLOGS_DIR} ];then
mkdir ${CLEARLOGS_DIR}
fi
rm "${DELETE_LOGS_LIST}" "${USER_LIST}" "${BIG_FILES_LIST}" &> /dev/null
touch "${DELETE_LOGS_LIST}" "${USER_LIST}" "${BIG_FILES_LIST}"
awk -F':' '{if($0 !~ /var/)print $1,$6}' /etc/passwd > "${USER_LIST}"
#!/bin/bash
SEARCH_DIR_LIST="search_"
SEARCH_TEMP_FILES="search_temp_"
SEARCH_FILES="search_"
file_size="100M"
if [ $(whoami) != 'root' ];then
printf "Please Use root to executen"
exit 1
fi
rm "${SEARCH_DIR_LIST}" "${SEARCH_TEMP_FILES}" "${SEARCH_FILES}" &> /dev/null
find / -maxdepth 2 ( -path '/proc' -o -path '/var' ) -prune -o -type d -print | grep '^/.*/'> "${SEARCH_DIR_LIST}"
printf "Begin search larger than ${file_size}M files,wait "
while read line
do
( find ${line} -type f -size +${file_size} -print >> "${SEARCH_TEMP_FILES}" ) &
done < "${SEARCH_DIR_LIST}"
wait
printf "End search larger than ${file_size}M files.n"
printf "Begin Compute each files detail size,"
while read line
do
awk -v filename=${line} -v filesize=$(stat -c %s ${line}) 'BEGIN{print filesize/1024/1024"M",filename}' >> ${SEARCH_FILES}
done < "${SEARCH_TEMP_FILES}"
wait
printf "End Compute each files detail size.n"
printf "Please Check "
cat ${SEARCH_FILES} | sort -rn
rm "${SEARCH_DIR_LIST}" "${SEARCH_TEMP_FILES}"
printf "Script execute end!n"
View Code
版权声明:本文标题:Linux系统提示Nospaceleftondevice解决方法 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/b/1711745303a608619.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论