LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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 02-21-2014, 09:07 PM   #1
your_shadow03
Senior Member
 
Registered: Jun 2008
Location: Germany
Distribution: Slackware
Posts: 1,466
Blog Entries: 6

Rep: Reputation: 51
Disk Usage Report Script


I have a Solaris script for showing disk usage as shown below:
Code:
home/l> space
                         SPACE OF IMPORTANT FILE SYSTEMS
------------------------------------------------------------------------
FILE-SYSTEM        TOTAL-SPACE     USED-SPACE      FREE-SPACE      %USED

/home                   4.75            2.23            2.52         47%
/outputs               32.00           15.27           16.73         48%
/backup                60.00           40.42           19.58         68%
/fns                   60.00           47.68           12.32         80%
/var                    5.00            3.04            1.96         61%
-------------------------------------------------------------------------
Color Significance for USED spaces:   gt-80 %  lt-80 % & gt-40 %  lt-40 %
Script:
Code:
home/> cat space
df -gt /tmp /home /outputs /backup /fns /var|awk 'BEGIN{
print "\t\t\t\033[1;43m SPACE OF IMPORTANT FILE SYSTEMS\t\033[m\n------------------------------------------------------------------------\n\033[1;45mFILE-SYSTEM \t TOTAL-SPACE \t USED-SPACE \t FREE-SPACE \t %USED\033[m\n"}
function disp(color_code,v1,v2,v3,v4,v5){
printf "\033[1;"color_code"m%-10s\t%10s\t%10s\t%10s\t%6s\033[m\n",v1,v2,v3,v4,v5
}
NR>2&&(($3>($2*.80)&&disp(31,$6,$2,$3,$4,$5))||($3>($2*.40)&&$3<($2*.80)&&disp(33,$6,$2,$3,$4,$5))||($3<($2*.40)&&disp(32,$6,$2,$3,$4,$5)))
END{print "-------------------------------------------------------------------------\nColor Significance for USED spaces:   \033[1;31mgt-80 % \033[m \033[1;33mlt-80 % & gt-40 %\033[m \033[1;32m lt-40 %\033[m"}'
Its not running on Linux as it doesnt detect df -gt command. Any idea how to get it run under Linux?
While I ran the script:
Code:
./space
df: invalid option -- 'g'
Try `df --help' for more information.
                 SPACE OF IMPORTANT FILE SYSTEMS
------------------------------------------------------------------------
FILE-SYSTEM      TOTAL-SPACE     USED-SPACE      FREE-SPACE      %USED

-------------------------------------------------------------------------
Color Significance for USED spaces:   gt-80 %  lt-80 % & gt-40 %  lt-40 %

Last edited by your_shadow03; 02-21-2014 at 09:09 PM.
 
Old 02-22-2014, 12:28 AM   #2
allend
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,371

Rep: Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750
Code:
df | grep 'Filesystem\|\/tmp\|\/home\|\/outputs\|\/backup\|\/fns\|\/var' | awk 'BEGIN{
print "\t\t\t\033[1;43m SPACE OF IMPORTANT FILE SYSTEMS\t\033[m\n------------------------------------------------------------------------\n\033[1;45mFILE-SYSTEM \t TOTAL-SPACE \t USED-SPACE \t FREE-SPACE \t %USED\033[m\n"}
function disp(color_code,v1,v2,v3,v4,v5){
printf "\033[1;"color_code"m%-10s\t%10s\t%10s\t%10s\t%6s\033[m\n",v1,v2,v3,v4,v5
}
NR>1&&(($3>($2*.80)&&disp(31,$6,$2,$3,$4,$5))||($3>($2*.40)&&$3<($2*.80)&&disp(33,$6,$2,$3,$4,$5))||($3<($2*.40)&&disp(32,$6,$2,$3,$4,$5)))
END{print "-------------------------------------------------------------------------\nColor Significance for USED spaces:   \033[1;31mgt-80 % \033[m \033[1;33mlt-80 % & gt-40 %\033[m \033[1;32m lt-40 %\033[m"}'
 
Old 02-22-2014, 11:18 PM   #3
your_shadow03
Senior Member
 
Registered: Jun 2008
Location: Germany
Distribution: Slackware
Posts: 1,466

Original Poster
Blog Entries: 6

Rep: Reputation: 51
The script is not displaying correctly.

Script:
Code:
df | grep 'Filesystem\|\/tmp\|\/home\|\/var/lib/psa\|\/opt\|\/var/log\|\/var' | awk 'BEGIN{
print "\t\t\t\033[1;43m SPACE OF IMPORTANT FILE SYSTEMS\t\033[m\n------------------------------------------------------------------------\n\033[1;45mFILE-SYSTEM \t TOTAL-SPACE \t USED-SPACE \t FREE-SPACE \t %USED\033[m\n"}
function disp(color_code,v1,v2,v3,v4,v5){
printf "\033[1;"color_code"m%-10s\t%10s\t%10s\t%10s\t%6s\033[m\n",v1,v2,v3,v4,v5
}
NR>1&&(($3>($2*.80)&&disp(31,$6,$2,$3,$4,$5))||($3>($2*.40)&&$3<($2*.80)&&disp(33,$6,$2,$3,$4,$5))||($3<($2*.40)&&disp(32,$6,$2,$3,$4,$5)))
END{print "-------------------------------------------------------------------------\nColor Significance for USED spaces:   \033[1;31mgt-80 % \033[m \033[1;33mlt-80 % & gt-40 %\033[m \033[1;32m lt-40 %\033[m"}'
Result:
Code:
./newdiskusage
                         SPACE OF IMPORTANT FILE SYSTEMS
------------------------------------------------------------------------
FILE-SYSTEM      TOTAL-SPACE     USED-SPACE      FREE-SPACE      %USED

/var             107340832         6996544        94892976          7%
                    139296         3779440              4%       /home
/tmp              16497160            1556        16495604          1%
-------------------------------------------------------------------------
Color Significance for USED spaces:   gt-80 %  lt-80 % & gt-40 %  lt-40 %
Its not displaying correctly.
 
Old 02-23-2014, 01:39 AM   #4
allend
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,371

Rep: Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750
Code:
grep 'Filesystem\|\/tmp\|\/home\|\/var/lib/psa\|\/opt\|\/var/log\|\/var'
You have changed the list of directories from those in your original post, so the grep pattern needs adjustment.
Are you really mounting volumes on /var/lib/psa and /var/log? If so, then properly escape the forward slashes in the grep pattern.
 
Old 02-23-2014, 06:53 AM   #5
your_shadow03
Senior Member
 
Registered: Jun 2008
Location: Germany
Distribution: Slackware
Posts: 1,466

Original Poster
Blog Entries: 6

Rep: Reputation: 51
All I want is to monitor /var/lib/psa/dumps, /home, /usr and /tmp directories.
The df shows below:

Code:
[root@u16868920 psa]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1              12G  2.5G  9.6G  21% /
/dev/mapper/vg00-usr  4.0G  2.1G  1.7G  57% /usr
/dev/mapper/vg00-var  103G  6.7G   91G   7% /var
/dev/mapper/vg00-home
                      4.0G  137M  3.7G   4% /home
none                   16G  1.6M   16G   1% /tmp
 
Old 02-23-2014, 07:09 AM   #6
allend
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,371

Rep: Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750Reputation: 2750
That shows why the script is failing. The output from /dev/mapper/vg00-home has been split across two lines.
As your script does not use the $1 field, you could modify the script to include the '--output' option to df and modify the field positions used by awk accordingly.
 
  


Reply



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
VPS, Disk usage report incorrect deeh514 Linux - Virtualization and Cloud 1 01-25-2011 05:11 AM
Script to give the disk usage in GB for each user. Tekken Linux - Server 2 09-08-2009 07:00 AM
script to get 100% cpu/disk usage sidra Programming 9 09-19-2007 04:26 AM
Script to monitor disk usage of a particular folder ajeetraina Linux - Server 3 07-20-2007 03:34 AM
Disk Usage Report joshnya Linux - Newbie 5 09-13-2005 08:58 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:43 AM.

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
Open Source Consulting | Domain Registration