Disk space script output in color

 
Thread Tools Search this Thread
Homework and Emergencies Emergency UNIX and Linux Support Disk space script output in color
# 22  
Old 02-09-2012
Use smtp-cli to sent html based mails
1> write script to check the utilization and convert your threshold to valid html syntax pass it to your message-body as variable .

--Shirish Shukla

---------- Post updated 02-09-12 at 05:11 AM ---------- Previous update was 02-08-12 at 09:14 AM ----------

Package : smtp-cli — command line SMTP client
smtp-cli Syntax :
/usr/bin/smtp-cli --disable-starttls --missing-modules-ok --host <SMTP-Server-IP>\
--port 25 --hello-host "$host" --from=" LINUX TEAM <linuxteam@mydomain.com>"\
--to="to-mail-id" --cc="cc-mail-id" --subject="Date $(date) .. Reports " --body-html="<html>
<body>
<font size=2 color=black face=arial>
Dear Team,

Thank You and Regards,<br />
Linux Team<br />
<hr align=left color=yellow width=36% />
</body>
</html>"

--Shirish

---------- Post updated at 05:11 AM ---------- Previous update was at 05:11 AM ----------

Package : smtp-cli &mdash; command line SMTP client
smtp-cli Syntax :
Code:
/usr/bin/smtp-cli --disable-starttls --missing-modules-ok --host <SMTP-Server-IP> --port 25 --hello-host "$host"\
 --from=" LINUX TEAM <linuxteam@mydomain.com>" --to="to-mail-id" --cc="cc-mail-id" --subject="Date $(date) ..\
 Reports " --body-html="<html>
<body>
<font size=2 color=black face=arial>
Dear Team,

Thank You and Regards,<br />
Linux Team<br />
<hr align=left color=yellow width=36% />
</body>
</html>"

--Shirish

Moderator's Comments:
Mod Comment Please use next time code tags for your code and data

Last edited by vbe; 02-09-2012 at 10:51 AM..
# 23  
Old 06-22-2012
Disk space report in colour

please paste here the code for displaying the report as i need it urgently.

Thanks ,
Kishore


FYI

I'm connecting to 15 servers in using ssh and storing disk space details of each server in a text file Finally , I'm emailing that text file at the particular id using mail -x . The report looks something like this.

Filesystem size used avail capacity Mounted on
/proc 0K 0K 0K 0% /proc
mnttab 0K 0K 0K 0% /etc/mnttab
fd 0K 0K 0K 0% /dev/fd
/dev/md/dsk/d30 7.9G 6.4G 1.4G 82% /var
swap 6.4G 32K 6.4G 1% /var/run
/dev/md/dsk/d60 269G 87G 179G 33% /u03
/dev/md/dsk/d40 4.8G 3.4G 1.3G 73% /home
swap 512M 456K 512M 1% /tmp
/dev/md/dsk/d54 20G 17G 2.5G 88% /u02
/dev/md/dsk/d53 5.9G 5.4G 507M 92% /u01


For file systems which have space greater than 90% , I want to display those in different color or in bold ...I just want to highlight those so that person reading email should get attention quickly to that filesystem but since I am storing the output in .txt file this is not achievable.I tried storing the output in .html file but could not succeed.Smilie Is there any easy way to achieve this ?
e.g. only the last row in the above report should be in red as below.
/dev/md/dsk/d53 5.9G 5.4G 507M 92% /u01

Thanks,
Ajay
# 24  
Old 06-22-2012
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

# 25  
Old 06-22-2012
https://www.unix.com/shell-programmin...#post302616905
See post #5 (A full featured color script!)
# 26  
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..
# 27  
Old 07-02-2012
Hi Yogor,

Your script runs perfect for me but i need to find the disk space of several machines from one central machine. how can we do that? in the script which u ha ve provided works for single machine.

Thanks
# 28  
Old 07-02-2012
Modify the script to do what you want.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
Login or Register to Ask a Question