Bashshell script exercises

Source: Internet
Author: User
1. determine disk space usage df-h | grep-vFile | sed's/% // G' | awk '{if ($5 & gt; 80) print "used space exceeds 80%:", $6} 'or #! /Bin/bash

1. Determine the disk space used


Df-h | grep-v File | sed's/% // G' | awk '{if ($5> 80) print "The used space exceeds 80% :", $6} 'or #! /Bin/bash # Filename: disk. sh # Date: 20110322 DISK_warn = 80 DISK_per = 'df-h | grep-v Filesystem | awk '{print int ($5 )} ''for I in $ DISK_per do if ["$ I"-gt "$ DISK_warn"]; then partion = 'df-h | grep "$ I %" | awk '{print $6} ''echo "used space exceeds 80%: $ partion" fi done


Determine whether the disk usage percentage has exceeded the set value. Here, you can change it to mail alarm.


2. Monitor CPU load


#! /Bin/bash # Filename: cpu_load.sh # Date: 20120322 LOAD_15 = $ (uptime | awk '{print $ NF }') CPU_num = $ (grep-c 'model name'/proc/cpuinfo) LOAD_avg = 'echo "scale = 2; a = $ LOAD_15/$ CPU_num; if (length () = scale (a) print 0; print a "| bc 'int_avg = 'echo $ LOAD_avg | cut-f 1-d ". "'load_warn = 0.70 if ($ INT_avg> 0); then echo" The average load of the current server for 15 minutes is $ LOAD_avg, exceeding the warning value of 1.0, please process "else LOAD_now = 'expr $ LOAD_avg \> $ load_warn' if (( $ LOAD_now = 1); then echo "The average load of the current server for 15 minutes is $ LOAD_avg, exceeding the warning value of 0.70. Please handle it in time. "Fi


Determine whether the cpu load exceeds the set value.

3. Monitor SWAP usage


#! /Bin/bash # Filename: swap. sh # Date: 20120322 TOTAL = $ (free-m | grep "Swap:" | awk '{print $2 }') USED = $ (FREE = $ (free-m | grep "Swap:" | awk '{print $3}') FREE = $ (free-m | grep "Swap: "| awk '{print $4}') SWAP_per =$ (expr $ FREE \ * 100/$ TOTAL) SWAP_warn = 50 if [$ SWAP_per-lt $ SWAP_warn]; then echo "the current server's SWAP space is available: $ free m, with less than 50% remaining. "fi


Determine whether the percentage used by swap exceeds the set value. Here, you can change it to mail alarm.

4. Use curl to determine whether the website can be accessed normally


#! /Bin/bash # Filename: web. sh # Date: 20110322 url =$ {1? "Enter the detected url address"} Status = $ (curl-s -- head $ url | awk '/HTTP/{print $2 }') [-z $ Status] & Status = 400 if ["$ Status"-eq 200]; then echo "$ the url can be accessed normally" else echo "$ the url cannot be accessed, please check! "Fi


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.