Tag:linux local resource
#!/bin/bash#created by liter on 2014/7/11path=/opt/jdk1.6.0_45/bin:/usr/local/sbin:/usr/ Local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/binexport path#cpu infoid_cpu= ' top -b -d 2 -n 10 | grep cpu | grep -v grep | cut -d ', ' -f 4 | tr -d -c ' 0-9.\n ' | sort -n | Head -n 1 ' use_cpu= ' echo "100-$id _cpu" &NBSP;|&NBSP;BC echo -e "\e[32m*********** \e[0m "echo -e " \e[1;42m cpu info \e [0m "echo -e " if ($id _cpu<=20) print \ "cpu has been used in \e[ 31m$use_cpu%, more than 80%\e[0m\n\ " else print \" CPU has been Used in \e[31m$use_cpu%, less than 80%\e[0m\n\ "" | bcecho -e "\e[ 32m********************* \e[0m "#MEM infototal_mem= ' Free -m | grep mem | tr -d -c ' 0-9 \n ' | tr -s ' ' | cut - d ' ' -f 2 ' used_mem= ' free -m | grep mem | tr -d -c ' 0-9 \n ' | tr -s ' ' | cut -d ' ' -f 3 ' Free_mem= ' free -m | grep mem | tr -d -c ' 0-9 \n ' | tr -s ' ' | cut -d ' ' -f 4 ' buffers_mem= ' free -m | grep Mem | tr -d -c ' 0-9 \n ' | tr -s ' ' | cut -d ' ' -f 6 ' cached_mem= ' free -m | grep mem | tr -d -c ' 0-9 \n ' | tr -s ' ' | cut -d ' ' -f 7 ' numerator=$[ $used _mem - $buffers _mem - $cached _mem ]float= ' echo "scale=2; $numerator/$total _mem" &NBSP;|&NBSP;BC ' int_float= ' echo "$float * 100" | &NBSP;BC ' echo -e "\e[1;42m mem info \e[0m" echo "total_mem is $total _ Mem m "echo " used_mem is $used _mem m "echo " true_used_mem is $numerator m "echo " buffers_mem is $buffers _mem m "echo " cached_mem is $cached _mem m "echo -e " if ($int _float>=80) print \ "Mem has been used in \e[31m$int_float%, more than 80%\e[0m\n\ " else print \" MEM has Been used in \e[31m$int_float%, less than 80%\e[0m\n\ "" | bcecho -e "\e[32m******************************************************* \e[0m" #SWAP infoecho -e "\E[1;42M&NBSP;SWAP&NBsp;info \e[0m "total_swap= ' free -m | grep swap | tr -d -c ' 0-9 \n ' | tr -s ' ' | cut -d ' ' -f 2 ' if [ $total _swap -eq 0 ];thenecho -e "\e[31mswap is unavailable\e[ 0m "elseused_swap= ' free -m | grep swap | tr -d -c ' 0-9 \n ' | tr -s ' ' | cut -d ' ' -f 3 ' free_swap= ' free -m | grep Swap | tr -d -c ' 0-9 \n ' | tr -s ' ' | cut -d ' ' -f 4 ' float_swap= ' echo ' scale=2; $used _swap/ $total _swap "&NBSP;|&NBSP;BC ' echo " total_swap is $total _swap m "echo " Used_swap is $used _swap m "percentage_swap= ' echo " float_swap * 100 "&NBSP;|&NBSP;BC" echo -e "Swap has been used in \e[31m$percentage_swap%\e[0m "fiecho -e " \e[32m****************************** \e[0m "#DISK INFOecho -e " \e[1;42m disk info \e[0m "df -thecho -e " \e[32m******************************************************* \e[0m "# passwd tableecho -e "\e[1;42m password table info \e[0m" passwd= "/root/. passwd "if [ ! -f " $passwd " ];thencp /etc/passwd /root/.passwdchattr +i /root/.passwdfidiff /root/.passwd /etc/passwdif [ $? -eq 0 ];thenecho -e "\e[31m/etc/passwd have no change\e[0m" elseecho -e "\e[31m/etc/passwd maybe changed\e[0m "fiecho -e " \e[32m***************************************************** ** \e[0m "
Run the sample (CPU, memory, swap, disk, password table information):
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/6B/D1/wKioL1U3sQ6wAB-nAAQJ0PLBlzs569.jpg "title=" 2015-04-22_222630.png "alt=" Wkiol1u3sq6wab-naaqj0plblzs569.jpg "/>
This article is from the "Rice Flowers in the Harvest" blog, please be sure to keep this source http://liter0015.blog.51cto.com/8746750/1637362
Linux system resources and account security monitoring scripts