LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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, 10:07 PM   #1
your_shadow03
Senior Member
 
Registered: Jun 2008
Location: Germany
Distribution: Slackware
Posts: 1,461
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 10:09 PM.
 
Old 02-22-2014, 01:28 AM   #2
allend
Senior Member
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware-current
Posts: 4,429

Rep: Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348
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-23-2014, 12:18 AM   #3
your_shadow03
Senior Member
 
Registered: Jun 2008
Location: Germany
Distribution: Slackware
Posts: 1,461
Blog Entries: 6

Original Poster
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, 02:39 AM   #4
allend
Senior Member
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware-current
Posts: 4,429

Rep: Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348
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, 07:53 AM   #5
your_shadow03
Senior Member
 
Registered: Jun 2008
Location: Germany
Distribution: Slackware
Posts: 1,461
Blog Entries: 6

Original Poster
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, 08:09 AM   #6
allend
Senior Member
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware-current
Posts: 4,429

Rep: Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348Reputation: 1348
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


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


All times are GMT -5. The time now is 10:19 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