Shell exercises (eight)

Source: Internet
Author: User

Exercise 1: Monitoring disk usage

Requirements: Write a shell script that detects all disk partition usage and inode usage and logs to a log file named after today's date, and notifies you when a partition capacity is found or the Inode usage is greater than 85%.

Idea: First Df-h then filter out the Used column, and then try to filter out the percentage of the integer part, and then 85 to compare, the same, the inode is the same idea.

Reference Answer:

#!/bin/bash# date: 2018 February 26 log=/var/log/disk/' date +%f '. logdate + '%F %T '  >   $LOGDF  -h >>  $logecho  >>  $LOGDF  -i >> $ Logemail= "[email protected]" #  disk partition usage for i in  ' df -h|awk  ' {print $5} ' | sed  ' s/%//' do    expr  $i  + 1 &>/dev/null     if [ $? -eq 0 ];thenif [  $i  -gt 50 ];then    python /root/shell/mail.py  "$email"   "disk test"   "' date + '%f %t ' '   disk warning ... '     fi    fidone# inode usage for  i in  ' df -i|awk  ' {print $5} ' |sed  ' s/%//' do    expr   $i  + 1 &>/dev/null    if [ $? -eq 0 ] ;then        if [  $i  -gt 2 ];then            python /root/shell/mail.py  "$email"   "disk test"   "' Date  + '%f %t '   disk inode warning ... '          fi    fidone

Mail Script mail.py:http://blog.51cto.com/11924224/2069732


Exercise 2: Statistics for ordinary users

Requirements: write a shell to see if your Linux system has custom users (ordinary users), if so, how many are there altogether? ( assuming that all ordinary users are UID greater than 1000 )

Reference Answer:



"The answer is released later!" 】

Shell exercises (eight)

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.