LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-16-2015, 12:46 PM   #1
Archangelmscj
LQ Newbie
 
Registered: Jun 2015
Posts: 12

Rep: Reputation: Disabled
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.
 
Old 10-16-2015, 03:57 PM   #2
estabroo
Senior Member
 
Registered: Jun 2008
Distribution: debian, ubuntu, sidux
Posts: 1,117
Blog Entries: 2

Rep: Reputation: 113Reputation: 113
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 }'
 
1 members found this post helpful.
Old 10-16-2015, 04:07 PM   #3
Archangelmscj
LQ Newbie
 
Registered: Jun 2015
Posts: 12

Original Poster
Rep: Reputation: Disabled
Genius estabroo....pure genius.....
 
Old 10-18-2015, 08:32 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,241

Rep: Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325
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.
 
Old 10-19-2015, 08:10 AM   #5
Archangelmscj
LQ Newbie
 
Registered: Jun 2015
Posts: 12

Original Poster
Rep: Reputation: Disabled
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......
 
Old 10-19-2015, 08:14 PM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,241

Rep: Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325
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.
 
Old 10-19-2015, 08:42 PM   #7
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,604

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
Quote:
Originally Posted by estabroo View Post
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...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Script to print range of numbers. First script raige Programming 2 11-15-2010 09:01 AM
print command monitoring novacrasher Programming 1 08-19-2010 04:23 AM
[SOLVED] Using UDEV to automatically run a script on optical disc mount? atavus Linux - Software 8 03-04-2010 10:48 PM
CUPS/Samba - Big Brother'ish Monitoring of Print Jobs Gort32 Linux - Software 1 02-26-2006 12:36 PM
Monitoring the print spool rmarvin Linux - Newbie 0 10-23-2003 03:21 PM


All times are GMT -5. The time now is 04:51 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration