Here it is:
df -h | grep -Eo [0-9]+% | sort -n | tail -1 | cut -d "%" -f1
To break if down:
- the "df -h" command shows you disk free info of all your partitions in human readable form
- the "grep -Eo [0-9]+%" command takes the output of the previous command and returns a list with only the percentages. It does this based on the -E option which stands for Extended Regex and the -o option which outputs only those characters that match the Regex.
- the "sort -n" command then takes the output from the previous command and sorts it ascending
- the "tail -1" command then takes the output from the previous command and shows only the last 1 line
- the "cut -d "%" -f1 cuts of the percentage sign, leaving you only with the number
The output of this could be used in another script that perhaps runs as a cron job every few times a day and based on the result, sends you an email. You can use your imagination I'm sure to see how this could be useful.
Happy Bashing!
No comments:
Post a Comment