From 597b03c3418450efb8db550e001b81fe3274cab7 Mon Sep 17 00:00:00 2001 From: robert Date: Fri, 2 Sep 2016 16:52:06 +0800 Subject: [PATCH] update --- README.md | 2 + shell/clean_haraka_logs.sh | 14 +++++++ shell/clean_logs_centos.sh | 32 +++++++++++++++ shell/clean_logs_ubuntu.sh | 26 ++++++++++++ shell/for.sh | 10 +++++ shell/system_status/System_info.sh | 63 ++++++++++++++++++++++++++++++ 6 files changed, 147 insertions(+) create mode 100644 shell/clean_haraka_logs.sh create mode 100644 shell/clean_logs_centos.sh create mode 100644 shell/clean_logs_ubuntu.sh create mode 100644 shell/system_status/System_info.sh diff --git a/README.md b/README.md index 8424b01..384b987 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,8 @@ kjyw 这里面的脚本是运维经常使用的脚本,方便大家使用! +相关使用文档:https://github.com/aqzt/kjyw/wiki + 如果您有好用的脚本,希望一起来分享,可以联系邮件ppabc#qq.com, 微信关注https://github.com/aqzt diff --git a/shell/clean_haraka_logs.sh b/shell/clean_haraka_logs.sh new file mode 100644 index 0000000..4a557de --- /dev/null +++ b/shell/clean_haraka_logs.sh @@ -0,0 +1,14 @@ +#!/bin/bash +## clean_haraka_logs 2016-09-02 +## http://www.aqzt.com +## email: ppabc@qq.com +## robert yu +## ubuntu + +#!/bin/bash +date=`date -d "-1 day" +%Y%m%d` +mkdir /data/haraka/$date/ +mv /var/log/haraka.log /data/haraka/$date/haraka.log.$date +/etc/init.d/haraka restart +find /data/haraka/ -name "20*" -type d -mtime +3|tee -a /home/haraka_del.txt|xargs rm -r 2>>/home/haraka_err.txt +echo ok \ No newline at end of file diff --git a/shell/clean_logs_centos.sh b/shell/clean_logs_centos.sh new file mode 100644 index 0000000..54d8358 --- /dev/null +++ b/shell/clean_logs_centos.sh @@ -0,0 +1,32 @@ +#!/bin/bash +## clean_logs 2016-09-02 +## http://www.aqzt.com +## email: ppabc@qq.com +## robert yu +## centos 6 + +rm -rf /var/log/audit/audit.* +rm -rf /var/log/secure-* +rm -rf /var/log/messages-* +rm -rf /var/log/spooler-* +rm -rf /var/log/yum.log-* +rm -rf /var/log/maillog-* +rm -rf /var/log/cron-* +rm -rf /var/log/btmp-* +rm -rf /var/log/dracut.log-* +rm -rf /var/log/dmesg.old + +cat /dev/null > /root/.bash_history +cat /dev/null > /var/log/anaconda.syslog +cat /dev/null > /var/log/anaconda.xlog +cat /dev/null > /var/log/dmesg +cat /dev/null > /var/log/lastlog +cat /dev/null > /var/log/syslog +cat /dev/null > /var/log/wtmp +cat /dev/null > /var/log/btmp +cat /dev/null > /var/log/maillog +cat /dev/null > /var/log/messages +cat /dev/null > /var/log/maillog +cat /dev/null > /var/log/secure +cat /dev/null > /var/log/cron +history -c diff --git a/shell/clean_logs_ubuntu.sh b/shell/clean_logs_ubuntu.sh new file mode 100644 index 0000000..327c980 --- /dev/null +++ b/shell/clean_logs_ubuntu.sh @@ -0,0 +1,26 @@ +#!/bin/bash +## clean_logs 2016-09-02 +## http://www.aqzt.com +## email: ppabc@qq.com +## robert yu +## ubuntu + +rm -rf /var/log/alternatives.log.* +rm -rf /var/log/auth.log.* +rm -rf /var/log/dmesg.* +rm -rf /var/log/dpkg.log.* +rm -rf /var/log/kern.log.* +rm -rf /var/log/syslog.* +rm -rf /var/log/ufw.log.* +rm -rf /var/log/wtmp.* +rm -rf /var/log/upstart/*.gz +rm -rf /var/log/upstart/*.log +cat /dev/null > /root/.bash_history +cat /dev/null > /var/log/dmesg +cat /dev/null > /var/log/lastlog +cat /dev/null > /var/log/syslog +cat /dev/null > /var/log/wtmp +cat /dev/null > /var/log/mail.log +cat /dev/null > /var/log/faillog +cat /dev/null > /var/log/udev +history -c \ No newline at end of file diff --git a/shell/for.sh b/shell/for.sh index 65270d8..71892c7 100644 --- a/shell/for.sh +++ b/shell/for.sh @@ -58,3 +58,13 @@ done ##批量修改文件后缀,conf改cfg for i in *.conf;do mv $i $(sed "s/conf/cfg/" <<<$i);done + + +##for循环每秒执行脚本 +#!/bin/bash +while true; do + sudo sh /data/shell/check_slave.sh + sleep 1 +done + + diff --git a/shell/system_status/System_info.sh b/shell/system_status/System_info.sh new file mode 100644 index 0000000..ef9e50a --- /dev/null +++ b/shell/system_status/System_info.sh @@ -0,0 +1,63 @@ +#!/bin/bash +disk_info () +{ + echo "======================disk info========================" + df -ThP|column -t +} + +cpu_info () +{ + echo "=======================cpu info========================" + echo "cpu processor is $(grep "processor" /proc/cpuinfo |wc -l)" + echo "cpu mode name is $(grep "model name" /proc/cpuinfo |uniq|awk '{print $4,$5,$6,$7,$8,$9}')" + grep "cpu MHz" /proc/cpuinfo |uniq |awk '{print $1,$2":"$4}' + awk '/cache size/ {print $1,$2":"$4$5}' /proc/cpuinfo |uniq +} + +mem_info () +{ + echo "=====================memory info========================" + MemTotal=$(awk '/MemTotal/ {print $2}' /proc/meminfo) + MemFree=$(awk '/MemFree/ {print $2}' /proc/meminfo) + Buffers=$(awk '/^Buffers:/ {print $2}' /proc/meminfo) + Cached=$(awk '/^Cached:/ {print $2}' /proc/meminfo) + FreeMem=$(($MemFree/1024+$Buffers/1024+$Cached/1024)) + UsedMem=$(($MemTotal/1024-$FreeMem)) + echo "Total memory is $(($MemTotal/1024)) MB" + echo "Free memory is ${FreeMem} MB" + echo "Used memory is ${UsedMem} MB" +} + +load_info () +{ + echo "=====================load info==========================" + Load1=$(awk '{print $1}' /proc/loadavg) + Load5=$(awk '{print $2}' /proc/loadavg) + Load10=$(awk '{print $3}' /proc/loadavg) + echo "Load in 1 min is $Load1" + echo "Load in 5 min is $Load5" + echo "Load in 10 min is $Load10" +} + +network_info () +{ + echo "=====================network info=======================" + network=$(ifconfig |grep "inet addr" |grep -v "127.0.0.1" |awk '{print $2}'|sed "s/addr://g") + echo "network eth0 IP is $network" +} + +network_card_info () +{ + echo "=====================network_card_info===================" + card=$(ip a|awk -F "inet|/" '/inet.*brd/ {print $2}') + echo "Network card is $card" +} + + + +disk_info +cpu_info +mem_info +load_info +network_info +network_card_info