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)