LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Disc Monitoring Script only print > 60% (https://www.linuxquestions.org/questions/linux-newbie-8/disc-monitoring-script-only-print-60-a-4175556354/)

Archangelmscj 10-16-2015 11:46 AM

Disc Monitoring Script only print > 60%
 
So I am new to scripting. What I am trying to accomplish it ssh into all my linux boxes and get their disc usage, print discs above 60%, then display it on a webpage. I like the format of df -HP displaying the headers. Searching through this website I came across this df -h | awk 'BEGIN { FS="[ %]*"} ($5+0) > 60 { print $NF } '. This is creditous to pan64, the keep it simple approach always works. Thus far I have replaced df-h with df-HP and changed { print $NF } to { print $FS } | cat >> /var/www/html/filename which gives most of what I am looking for. The only thing I am missing is the header information such as Filesystem, Size, Used, Avail, Use%, and Mounted on. If you can please point me in the right direction as how to get this information displayed, that will be greatly appreciated? From there I will figure out how to get the hostname with a break then with the above info. Ultimately trying to get the scrip to format it like this....

Hostname
-----------------
df -HP information (week 1)
df -HP information (week 2)

Hostname
---------------
Same as above.

estabroo 10-16-2015 02:57 PM

How about adding a check for Use that should cause it to dump the header as well:

df -HP | awk 'BEGIN { FS="[ %]*"} ($5+0) > 60 { print $FS } $5=="Use" { print $FS }'

Archangelmscj 10-16-2015 03:07 PM

Genius estabroo....pure genius.....

chrism01 10-18-2015 07:32 PM

Ca I just point out that over time its going to get hard to read a wall of text ... How about something like Nagios (for alarming you if percentage exceeds eg 90) and Cacti (trend graphing so you can easily see at a glance what state ALL the disks are/have been in).

There are alternatives to both of these tools, but you get the idea.

Archangelmscj 10-19-2015 07:10 AM

Thank you chrism01...I will look into these solutions. I was going to add to the script to send out an alert if disc utilization hits 90%. If these solutions makes things easier. Well then......

chrism01 10-19-2015 07:14 PM

Well, its possible to write your own scripts and that can be educational, but for more than a few systems/disks I'd recommend a tool built for the job.

jpollard 10-19-2015 07:42 PM

Quote:

Originally Posted by estabroo (Post 5435701)
How about adding a check for Use that should cause it to dump the header as well:

df -HP | awk 'BEGIN { FS="[ %]*"} ($5+0) > 60 { print $FS } $5=="Use" { print $FS }'

or something simple:

df -HP | head -1

Which will output only the heading...


All times are GMT -5. The time now is 01:41 PM.