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


本文标签: 自动 作者 生成