Sponsored Content
Homework and Emergencies Emergency UNIX and Linux Support Disk space script output in color Post 302661957 by kishore.becit on Tuesday 26th of June 2012 02:37:53 AM
Old 06-26-2012
Disk space report in colour

Quote:
Originally Posted by Ygor
I've just merged a couple of old scripts to create a graphical html report from df and to send inline html via sendmail...
Code:
#!/bin/sh

#---create report
(
  echo '<HTML><HEAD><TITLE>STATS</TITLE></HEAD><BODY>'
  echo '<H3>'$(uname -n)'</H3><TABLE BORDER=2 CELLSPACING=0 CELLPADDING=2>'
  echo '<TR><TH>Filesystem</TH><TH>1048576-blocks</TH><TH>Used</TH>'
  echo '<TH>Available</TH><TH>Capacity</TH><TH>Mounted On</TH></TR>'
  df -Pml |awk 'NR>1 && NF==6'|sort|while read FS SIZE USED FREE PERC MOUNT
  do
    PERCENT=${PERC%%%}
    if [[ $PERCENT -gt 90 ]]
    then
         COLOR=red
    else
         COLOR=black
    fi
    echo '<TR><TD>'$FS'</TD><TD ALIGN=RIGHT>'$SIZE'</TD>'
    echo '<TD ALIGN=RIGHT>'$USED'</TD><TD ALIGN=RIGHT>'$FREE'</TD>'
    echo '<TD><TABLE BORDER=0 CELLSPACING=1 CELLPADDING=0><TR>'
    echo '<TD WIDTH='$((2 * $PERCENT))' BGCOLOR="'$COLOR'"></TD>'
    echo '<TD WIDTH='$((2 * (100 - $PERCENT)))' BGCOLOR="gray"></TD>'
    echo '<TD><FONT SIZE=-1 COLOR="'$COLOR'"> '$PERC'</FONT></TD>'
    echo '<TR></TABLE></TD><TD>'$MOUNT'</TD></TR>'
  done
  echo '</TABLE><P>Generated at '$(date '+%H:%M on %d-%b-%y')'</BODY></HTML>'
) > /tmp/df.html

#---email report
export MAILTO="unix@mailinator.com"
export SUBJECT="Report"
export BODY="/tmp/df.html"
(
 echo "To: $MAILTO"
 echo "Subject: $SUBJECT"
 echo 'MIME-Version: 1.0'
 echo 'Content-Type: multipart/mixed; boundary="-q1w2e3r4t5"'
 echo
 echo '---q1w2e3r4t5'
 echo 'Content-Type: text/html'
 echo 'Content-Disposition: inline'
 cat $BODY
 echo '---q1w2e3r4t5--'
) | /usr/sbin/sendmail $MAILTO



But in this code, i didn't find any connections to several linux machines.where to give connection related credentials in this code?
kindly help me

And the code works perfect for single linux machine. But i wnat report for multiple machines in the same report. Help me plz.

Last edited by kishore.becit; 06-26-2012 at 03:49 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Disk space script

Hi all, Can any one help me in making a disk space script in solaris 8/9 for instance i only want to get those partitions whose diskspace has exceed 70%. Any volunteer? Cheers! BR/asad (8 Replies)
Discussion started by: asadlone
8 Replies

2. Shell Programming and Scripting

Script for Disk space

:( Hi All, i have 4 linux server for which i want set up script to monitor the disk space ... here my problem is i want the output like graph... also it should reflect in monitor ...as non stop process.. can any one suggest me any way where i can implement the script? ... (3 Replies)
Discussion started by: Shahul
3 Replies

3. Shell Programming and Scripting

putting color on output file script

do you have any simple script on how to change the color and font of a string in a script example echo "====================================" echo " sample color script" echo "====================================" echo " hello " echo " bye" on hello,... (3 Replies)
Discussion started by: lhareigh890
3 Replies

4. Shell Programming and Scripting

Append color in shell script for output

Hi Experts, I want to get my shell script output in a color for a particular word. PFB my output. TT.QM.JTV1S1 TLORSBT2.JMR701T1.C1 REPOS TT.QM.JTV1R1 TLORSBF2.JMR701T1.C1 NORMAL whenever REPOS word comes then entire line should come in red color. Can you please help me... (4 Replies)
Discussion started by: darling
4 Replies

5. Shell Programming and Scripting

Disk Space Output

I am very new to unix and Linux, So I have a question about LINUX and AIX. What LINUX and AIX commands can be used to get the following output: 071912 GB blocks Free %Iused Mounted on 071912 5.00 4.64 8% / 071912 15.00 9.44 38% /usr 071912 6.00 2.56 58% /var 071912 15.00 12.88 15% /tmp... (1 Reply)
Discussion started by: najeemsarwat
1 Replies

6. Shell Programming and Scripting

Color encoding on the disk space script

Hi All, Hope all are doing good!! Am glad that i have utilized some ideas and written a code to make the disk space result comes better and it was successfully running in the production. The next update from my manager was to make this code to come in a table format with color added. 1)... (28 Replies)
Discussion started by: Kalaihari
28 Replies

7. Shell Programming and Scripting

Disk Space Script to direct output

Hi, I am working on Sun Solaris 5.10 and want to direct the output from a disk space check script to an output file; #!/bin/bash CURRENT=$(df -k /log/logs | grep /log/logs | awk '{ print $5}' | sed 's/%//g') THRESHOLD=30 if ; then echo "Remaining free space is low" > output.txt else... (10 Replies)
Discussion started by: SSKAAB
10 Replies

8. Shell Programming and Scripting

I need help!! disk free space script

i want to write a shell script,when disk uses is 90% then automatically send a email to distribution list (group member)...... (1 Reply)
Discussion started by: sonu pandey
1 Replies

9. UNIX for Beginners Questions & Answers

Cutting disk space output

Running this code df -h | head -2 | awk '{print $8}' Gives me the following output: %iused 6% What I'm trying to do is get the 6% but I'm having trouble doing this using cut -c, I think that this could be because the text is on different lines; is there a way of doing this? (8 Replies)
Discussion started by: $shell_Learner
8 Replies

10. UNIX for Beginners Questions & Answers

Disk space script

i have 3 servers and i am checking for the disk space of a specific mount-point, should not be more than 85 % considering example as below server1 mountpoint_1 has 70% diskutilization server2 mountpoint_1 has 80% diskutilization server3 mountpoint_1 has 7% diskutilization now when it... (6 Replies)
Discussion started by: abhaydas
6 Replies
DUREP(1)						    Disk Usage Report Generator 						  DUREP(1)

NAME
durep - disk usage report generator SYNOPSIS
durep [OPTIONS]... [DIRECTORY] DESCRIPTION
durep creates disk usage reports with bar graphs, allowing one to easily deduce which directories are using the most space. Although durep can produce text output similar to du, its real power lies in the ability to store reports in a file, which can then be viewed as a web page with the supplied cgi script. OPTIONS
Options are grouped into three distinct sections. Text Output Options These options are for controlling the text report output. -td, --text-depth=N Limit text report on directories to depth N. No directories below this level will be shown in the report. -hs, --hide-size=N[bkmg] Do not display entries using N Bytes/KB/MB/GB or less (default Bytes). This is to reduce clutter in the reports. It allows you to remove small files from the text report. -sd, --show-date Display the modification date of the file or directory in the report. -ns, --nosort Do not sort results by size. Leaves results in the order in which they were scanned, which is highly dependent on the file system. -q, --quiet Do not produce text output. This stops the creation of a text report, and is useful when you are only interested in generating a save-file for use with the web report. File Options These options control load and save files. -sf, --save-file=FILE Save the results of the scan into this file. This can be loaded for a text report, but is generally used by the cgi script to display web reports. The filename should end in .ds (it is appended if it does not). -lf, --load-file=FILE Load the results of a scan from this file. This takes the place of scanning a directory. Inclusion options (described below) will not take effect if this option is used. -d, --desc=DESCRIPTION Give a description to be stored in the save-file. This is displayed on the web report summary page. -c, --collate==DIR Collate the save-files in the given directory. This creates a durep.cds file, which is used by the cgi script to manage and display save-files. See Web Reports section below for more detail. Inclusion Options These options control which directories and files should be included in the report. -f, --files Do not descend into sub-directories, only report files. -x, --one-file-system Do not traverse file systems. This is similar to the -x option for du, allowing easy checking of an entire file system such as /. -cp, --collapse-path=PATTERN Hide entries below paths that match PATTERN. This allows you to conceal the contents of certain directories in the report. You may wish perhaps to show home directories in a report but not show their content in which case you could use the option "-cp '/home'". -ep, --exclude-path=PATTERN Ignore paths that match PATTERN. This works in a similar manner to "-cp" above, except it excludes the directory from the scan itself. -cf, --coalesce-files==N[bkmg] Coalesces entries for files below the given size into one entry. This is useful for reducing clutter in reports. WEB REPORTS
Since version 0.9, durep no longer directly generates html files for its web reports. It now uses a cgi script that reads data from save- files. The script will handle multiple save-files, potentially from multiple hosts, so you can consolidate your reports into one place. Copying save-files from other hosts is left as an exercise for the reader. It is necessary to collate the save-files before viewing them via the cgi script. This process creates the file "durep.cds" which contains meta-data about all of the save-files. From this a summary page is shown where you can choose which report you wish to view. The collation must be done any time a save-file is added or overwritten. The cgi-script has some configurable variables at the top. These tell the script where to look for the css file and the graphic used for the bar graphs. There are also options to set whether the modification date, and/or the options used to create the save-file should be shown. These are both set to 1 by default. As always, you should take care when installing the cgi script. I've done my best, but I make no guarantees about its security. It would probably be unwise to allow this script to be accessed from the Internet at large. EXAMPLES
1. durep -td 2 This would print the directory tree starting from the current directory to depth 2. 2. durep -f /var/spool/mail This might be useful for keeping a check on the mail directory. The "-f" switch tells durep to just scan files and not descend into directories. 3. durep -x -cp "/(etc|usr/share)" -ep "/var" -sf /var/lib/durep/root.ds / This more complicated version does the following. It scans the root file system only, collapses the contents of any paths beginning /etc or /usr/share and skips the contents of the /var directory. It saves the output of this report into the file /var/lib/durep/root.ds. No text report is produced. 4. durep -lf /var/lib/durep/root.ds -hs 1m This reads the save-file /var/lib/durep/root.ds and produces a text report from it, hiding any files below 1 megabyte. 5. durep -c /var/lib/durep This collates any save-files in /var/lib/durep. SEE ALSO
du(1), perl(1) AUTHOR
Damian Kramer <psiren@hibernaculum.net> durep version 0.9 2012-05-12 DUREP(1)
All times are GMT -4. The time now is 09:07 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy