Rate this post
Администратору приходится регулярно выполнять одну и ту же работу по обслуживанию и проверке сервера. К таким работам относится проверка сервера на вирусы, проверка рейда, диска, наличие обновлений.nnДанный скрипт проведет все проверки в автоматическом режиме и сформирует краткий отчет аудит сервера. Можно добавить в крон и отправлять результат на почту.n
Если Вам необходимо провести аудит сервера, обращайтесь [email protected]
n
#!/bin/bashnn# Am I root?nif [ "x$(id -u)" != 'x0' ]; thennecho 'Error: this script can only be executed by root'nexit 1nfinnecho ================================================================================nnecho "Hostname: $HOSTNAME"nnif [ -x "$(command -v lsb_release)" ]; thennecho Detected OS: $(lsb_release -si) $(lsb_release -sr) $(uname -m)nfinnecho -n "Detected package manager: "nif [ -x "$(command -v apt-get)" ]; thennTYPE="apt"necho APT basednelif [ -x "$(command -v yum)" ]; thennTYPE="yum"necho RPM basednelsenecho UNKNOWnfinnecho ================================================================================nnecho Network devices:nifconfig | awk -v RS="\n\n" '{ for (i=1; i<=NF; i++) if ($i == "inet" && $(i+1) ~ /^addr:/) address = substr($(i+1), 6); if (address != "127.0.0.1") printf "%s\t%s\n", $1, address }'nnecho ================================================================================nnecho -n "Updates available: "nif [[ "$TYPE" == "yum" ]]; thennyum -q check-updatenelif [[ "$TYPE" == "apt" ]]; thennapt-get --just-print upgrade 2>&1 | perl -ne 'if (/Inst\s([\w,\-,\d,\.,~,:,\+]+)\s\[([\w,\-,\d,\.,~,:,\+]+)\]\s\(([\w,\-,\d,\.,~,:,\+]+)\)? /i) {print "PROGRAM: $1 INSTALLED: $2 AVAILABLE: $3\n"}'nfinnecho ================================================================================nnecho "Check S.M.A.R.T. for all HDD: "nif [ -x "$(command -v smartctl)" ]; thennlspci | egrep -i 'raid|adaptec'nALLDRIVES=$(smartctl --scan-open | awk '{print $1}')nfor DRIVE in $ALLDRIVESndonecho --------------------------------------------------------------------------------necho $DRIVE:nsmartctl -H $DRIVE | grep -i "health"nsmartctl -A $DRIVE | egrep -i "(RAW_VALUE|Pre-fail|Pending|Temperature)"ndonenelsenecho 'ERROR: smartmontools is not installed.' >&2nfinnecho ================================================================================nnecho "MD RAID stats: "nif [ -f /proc/mdstat ]; thenncat /proc/mdstatnelsenecho 'ERROR: mdstat is not found.' >&2nfinnecho ================================================================================nnecho "Update ClamAV virus databases: "nif [ -x "$(command -v freshclam)" ]; thennfreshclamnelsenecho 'ERROR: freshclam is not installed.' >&2nfinnecho --------------------------------------------------------------------------------nnecho "Scan for viruses with ClamAV: "nif [ -x "$(command -v clamscan)" ]; thennclamscan -ir --exclude-dir=^/sys\|^/proc\|^/dev /nelsenecho 'ERROR: clamscan is not installed.' >&2nfi