Disk space script output in color

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

use sendmail

Thanks itkamaraj but will that display o/p in color for particular condition (> 90% ) ?

you need to form a html output

try the below one for test

html file contents

output.html

 
<html>
<body>
<font color=red><b>90%</b></font>
</body>
</html>

Shell script

 
 
(
echo "From: abcd@abcd.com"
echo "To: abcd@abcd.com"
echo "MIME-Version: 1.0"
echo "Subject: Test"
echo "Content-Type: text/html"
cat output.html
) | sendmail -t

Thanks I am getting

sendmail: not found

I am using
>uname -a
SunOS ssdb0043 5.9 Generic_122300-60 sun4u sparc SUNW,Sun-Fire-V240

hmm.. without sendmail.. i am not sure.. but found this below code in google. just give a try.

html file :file.html

From: some.user@other.machine
Subject: Test
MIME-Version: 1.0
Content-Type: multipart/mixed;
        boundary="----_=_NextPart_000_01C5B90C.9F15F690"
------_=_NextPart_000_01C5B90C.9F15F690
Content-Type: text/html;
        charset="iso-8859-1"
<!DOCTYPE html PUBliC "-//W3C//DTD html 4.0 Transitional//EN">
<html>
  <head>
    <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
  </head>
  <body>
    <div>
      <b>
Testing 1 2 3.
     </b><br>
    </div>
  </body>
</html>

shell code

 
(cat file.html | mailx user@some.machine)

You get a useless use of cat award.

mailx user@some.machine < file

3 Likes

No this is also not working ...if not in color can we have specific part of the output differentiated in some way ...may be in bold or in different font ..

No, you cannot do bold and other cosmetic changes ( color, bold, underline...etc.. ) with the mail and mailx command.

http://www.unix.com/unix-advanced-expert-users/37480-display-html-text-body-using-unix-mailx.html

What program are you using to read mail? Did you get ANY mail from the "cat" experiment?

---------- Post updated at 09:18 AM ---------- Previous update was at 09:16 AM ----------

try /usr/lib/sendmail or /usr/sbin/sendmail instead of mail mailx

I actually got output email but it was not HTML formatted .. the output came in the email like this..
From: some.user@other.machine
Subject: Test
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="----_=_NextPart_000_01C5B90C.9F15F690"
------_=_NextPart_000_01C5B90C.9F15F690
Content-Type: text/html;
charset="iso-8859-1"
<!DOCTYPE html PUBliC "-//W3C//DTD html 4.0 Transitional//EN"> <html>
<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
</head>
<body>
<div>
<b>
Testing 1 2 3.
</b><br>
</div>
</body>
</html>

charset="iso-8859-1"

should be on the same line as Content-Type. Somehow it got cut into two lines during the multiple copy/pastes. Change the "From" address and use sendmail and try again.

@otheus

Ajay doesnt have sendmail command

itkamaraj I have sendmail command ...trying it now.

this seems to be a weird way to monitor the disk usage of your servers.

why don't you just send mails with the filesystems with a usage greater 90%? then you don't have to read through all filesystems

if this systems are in your responsibility, consider using a monitoring tool such as xymon

red : Xymon - Status @ Thu Dec 29 11:01:22 2011

and trigger mails from the monitoring server

@funksen -- maybe he wants a "hard copy" of the daily report of the usage, not only when it gets low.

Hi funksen, Thanks all these servers belong to our client so he may not allow us to install such tools. Even he does there is lot of approval process which takes few months of time.
We initially thought of sending mails only of file systems > 90% but what our management is really looking at is a daily complete well formatted report.

-Ajay

Hi..Can anyone provide me the script content as well?

@ajaypatil_am Did you get sendmail to send you the MIME-formatted mail? If so, the next step is fairly trivial.

sorry for confusion ...i do not have sendmail. :mad:
> which sendmail
no sendmail in /opt/app/xxxxx.......

anyway to achieve the same using perl.