Operating System - HP-UX
1753797 Members
7524 Online
108805 Solutions
New Discussion юеВ

File System check script issue with HP

 
NikolasCy
Collector

File System check script issue with HP

#! /bin/ksh  -vx
#FS ALERT generation script

export threshold=90
export configFile=/mtrnas/mtr/users/tooladm/scripts/FS_ALERT/Disk_Space_Check_Config.cfg
getList()
{
for i in `cat $configFile`
do
rHost=`echo $i|cut -d: -f1`
rFileSys=`echo $i|cut -d: -f3`
rUser=`echo $i|cut -d: -f4`
rOwn=`echo $i|cut -d: -f5`
echo ${rUser} ${rHost} ${rFileSys} `ssh ${rUser}@${rHost} df -h ${rFileSys}` $rOwn
done |cut -f15,1,2,3,12,13,14,17 -d' '|awk '{ print $7" "$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8 }'|sort -nr|cut -f2,3,4,5,6,7,8,9 -d' '|tr -d '%'
}

getList
printTable()
{

getList|cut -f2,3,4,5,6,7,8 -d' ' |awk '
BEGIN { print "<table id=design> <tr><th>Machine<th>File System<th>Size<th>Used<th>Avail<th>Used<th>Owner Team</tr>" }
{
if ( NR%2 )
print "<tr class=alt>"
else
print "<tr>"
print "<td>"$1"<td>"$2"<td>"$3"<td>"$4"<td>"$5
        if ( $6 < 75 )
print "<td><img src=\"http://chart.apis.google.com/chart?chf=a,s,0000005A|bg,s,BFD0F1&chbh=a&chs=100x10&cht=bhs&chco=7BCC70&chd=t:"$6"\" width=100 height=10 >"$6"%"
        else if ( $6 < 90 )
print "<td><img src=\"http://chart.apis.google.com/chart?chf=a,s,0000005A|bg,s,BFD0F1&chbh=a&chs=100x10&cht=bhs&chco=FFFF00&chd=t:"$6"\" width=100 height=10 >"$6"%"
        else
print "<td> <img src=\"http://chart.apis.google.com/chart?chf=a,s,0000005A|bg,s,BFD0F1&chbh=a&chs=100x10&cht=bhs&chco=FF0000&chd=t:"$6"\" width=100 height=10 >"$6"%"
print "<td>" $7
print "</tr>"
}
END { print "</table>" }
'
}
printInstructions()
{
echo "<br><table id=design><tr><th>Activity<th>Command<th>Example</tr>"
echo "<tr><td>Check the available space on FS<td>df -k .<td>mtrapi32@illin4942:/mtruser/mtr/subsystest/mtrapi32> df -k ."
echo "<tr><td>Check space occupied by an Account<td> du -sk acct-name<td>mtrapi32@illin4942:/mtruser/mtr/subsystest> du -sk mtrapi32"
echo "<tr><td>Find file with specific name not accessed for last 7 days<td>find . -type f -name file-name -mtime +7 | xargs ls -lart<td>mtrapi32@illin4942:/mtruser/mtr/subsystest/mtrapi32>find . -type f -name 'weblogic_console*' -mtime +7 | xargs ls -lart"
}

printDetail()
{

#echo "<br><table id=design><tr><th>Host<th>FileSystem<th>Details</tr>"
for i in `getList|cut -f1,2,3,7,8 -d' '|sed 's/ /#/g'`
do
rm -rf /ecrusrs1/blc/aimsys/hftool/Script/"ST&SST&CSM_Team.html"
rm -rf /ecrusrs1/blc/aimsys/hftool/Script/API_Team.html
rm -rf /ecrusrs1/blc/aimsys/hftool/Script/ST_Team.html
rm -rf /ecrusrs1/blc/aimsys/hftool/Script/SST_Team.html
rm -rf /ecrusrs1/blc/aimsys/hftool/Script/"UT&GSS_Team.html"
rm -rf /ecrusrs1/blc/aimsys/hftool/Script/"ST&CRM_Application.html"
rm -rf /ecrusrs1/blc/aimsys/hftool/Script/GSS_Team.html
rm -rf /ecrusrs1/blc/aimsys/hftool/Script/AMSS_Team.html
rm -rf /ecrusrs1/blc/aimsys/hftool/Script/EPC_Team.html
rm -rf /ecrusrs1/blc/aimsys/hftool/Script/API_Storage.html

rUser=`echo $i|cut -f1 -d#`
rHost=`echo $i|cut -f2 -d#`
rFS=`echo $i|cut -f3 -d#`
rPer=`echo $i|cut -f4 -d#`
rOwn=`echo $i|cut -d "#" -f5`
mDL=`grep :$rOwn: /mtrnas/mtr/users/tooladm/scripts/FS_ALERT/Mail_DL.cfg | cut -d ":" -f6`
mInstLog=/mtrnas/mtr/users/tooladm/scripts/FS_ALERT/Ins.html
export cutoff=90
if [ $rPer -gt $cutoff ]
then
mLogName=/mtrnas/mtr/users/tooladm/scripts/FS_ALERT/$rOwn.html
echo "<table border=1>" >> ${mLogName}
echo "<tr><td bgcolor=#A7C942 style=color:LemonChiffon><b>Host<\b><td bgcolor=#A7C942 style=color:LemonChiffon><b>FS<\b><td bgcolor=#A7C942 style=color:LemonChiffon><b>Percentage Used<\b><td bgcolor=#A7C942 style=color:LemonChiffon><b>Owner<\b>">> ${mLogName}
echo "<tr><td>$rHost<td>$rFS<td>$rPer<td>$rOwn">>${mLogName}
chk=`ssh ${rUser}@${rHost} "cd ${rFS} ; du -sk * | sort -n | tail -5 | sed 's/ /#/g'`
mchk=`echo $chk | sed 's/ /#/g'`
export size1=`echo $mchk | cut -d "#" -f1`
m1size=`echo $size1/1024/1024 | bc`
export m1acct=`echo $mchk | cut -d "#" -f2`
export size2=`echo $mchk | cut -d "#" -f3`
m2size=`echo $size2/1024/1024 | bc`
export m2acct=`echo $mchk | cut -d "#" -f4`
export size3=`echo $mchk | cut -d "#" -f5`
m3size=`echo $size3/1024/1024 | bc`
export m3acct=`echo $mchk | cut -d "#" -f6`
export size4=`echo $mchk | cut -d "#" -f7`
m4size=`echo $size4/1024/1024 | bc`
export m4acct=`echo $mchk | cut -d "#" -f8`
export size5=`echo $mchk | cut -d "#" -f9`
m5size=`echo $size5/1024/1024 | bc`
export m5acct=`echo $mchk | cut -d "#" -f10`
( echo "Subject: BC: FS Utilisation Alert"
         echo "From: metroinfraintegration@tlv.amdocs.com"
         #echo "From: talash@tlv.amdocs.com"
        # echo "To: ${mDL}"

        echo "To: nikolas.iakovides@amdocs.com"
echo "MIME-Version: 1.0"
         echo "Content-Type: text/html"
         echo "Content-Disposition: inline"
         echo '<HTML><BODY><PRE>'
echo "Please clean the accounts on the following FS immediately"
cat $mLogName
echo '</PRE></BODY></HTML>'
echo '<HTML><BODY><PRE>'
echo 'Accounts occupying Maximum Space are:'
echo '<table border=1>'
echo '<tr><td bgcolor=#A7C942 style=color:LemonChiffon><b>Size(GB)<\b><td bgcolor=#A7C942 style=color:LemonChiffon><b>Account<b><\b>'
echo '<tr><td>'
echo ${m5size}
echo '<td>'
echo ${m5acct}
echo '<tr><td>'
echo ${m4size}
echo '<td>'
echo ${m4acct}
echo '<tr><td>'
echo ${m3size}
echo '<td>'
echo ${m3acct}
echo '<tr><td>'
echo ${m2size}
echo '<td>'
echo ${m2acct}
echo '<tr><td>'
echo ${m1size}
echo '<td>'
echo ${m1acct}
echo '</PRE></BODY></HTML>'
echo '<HTML><BODY><PRE>'
echo 'Threshold Space per Product:'
echo '<table border=1>'
echo '<tr><td bgcolor=#A7C942 style=color:LemonChiffon><b>Product<\b><td bgcolor=#A7C942 style=color:LemonChiffon><b>Space requirement(GB)<\b>'
echo '<tr><td>ENS<td>10'
echo '<tr><td>API<td>2'
echo '<tr><td>AMSS<td>10'
echo '<tr><td>CRM<td>4'
echo '<tr><td>EPC<td>5'
echo '</table>'
echo '</PRE></BODY></HTML>'
echo '<HTML><BODY><PRE>'
echo '<nbsp style="font-family:verdana;color:red;">'
echo '<b>'
echo 'Useful Commands'
echo '</b>'
echo '</nbsp>'
echo '<table border=1>'
echo '<tr><td bgcolor=#A7C942 style=color:LemonChiffon><b>Activity<\b><td bgcolor=#A7C942 style=color:LemonChiffon>Command<b><\b><td bgcolor=#A7C942 style=color:LemonChiffon><b>Example<\b>'
echo '<tr><td>Check the available space on FS<td>df -k .<td>mtrapi32@illin4942:/mtruser/mtr/subsystest/mtrapi32> df -k . '
echo '<tr><td>Check space occupied by an Account<td> du -sk acct-name<td>mtrapi32@illin4942:/mtruser/mtr/subsystest/mtrapi32> du -sk mtrapi32'
echo '<tr><td>Find file with specific name not accessed for last 7 days<td>find . -type f -name file-name -mtime +7 | xargs ls -lart<td>mtrapi32@illin4942:/mtruser/mtr/subsystest/mtrapi32>find . -type f -name "weblogic_console*" -mtime +7 | xargs ls -lart'
echo '</table>'
echo '</PRE></BODY></HTML>'
 ) | /usr/sbin/sendmail ${mDL}
fi
[ $rPer -lt $threshold ] && continue
echo "<tr><td>$rHost<td>$rFS<td><table border=0>"
ssh ${rUser}@${rHost} "cd ${rFS} ; du -sk * 2>/dev/null|sort -n" | awk ' { print "<tr><td>"$1"<td>"$2"</tr>" } '
echo "</table>"
done
echo "</table><br>"

}

/usr/lib/sendmail -t <<EOF
From: someone@company.com

To: someoneelse@company.com
Subject: File System Usage Report
Content-Type: text/html; charset="us-ascii"
<html><head>
<style type="text/css">
#design
{
font-family:"Trebuchet MS", Arial, Helvetica, sans-serif;
border-collapse:collapse;
}
#design td, #design th
{
font-size:1em;
border:1px solid #98bf21;
padding:3px 7px 2px 7px;
}
#design th
{
font-size:1.1em;
text-align:left;
padding-top:5px;
padding-bottom:4px;
background-color:#A7C942;
color:#ffffff;
}
#design tr.alt td
{
color:#000000;
background-color:#EAF2D3;
}</style></head>
<body>
<table border=0>
<tr>
<img src=http://hpxi011:10003/manager/images/fs_banner.png>
</tr>
<tr>
`printTable`
`printDetail`
<p style="font-family:verdana;color:red;">
<b>
Useful Commands </b></p>
`printInstructions`
</tr>
</table>
</body>
</html>
EOF

illin4942:90:/mtruser/mtr/subsystest:mtrapi32:ALL_TEAMS
illin4940:90:/mtrtstuser/mtr/test:mtrenv32:ALL_TEAMS
illin4940:90:/mtrtuxhome/mtr/test:mtroln32:ALL_TEAMS
snm503:90:/mtrsubtstamsshome/mtr/test:mtrams32:ALL_TEAMS
illin589:90:/mtrusers1/dev/aimsys:cache32:ALL_TEAMS
illin762:90:/opt/INFRA/MSOA:wpsadm:ALL_TEAMS
illin762:90:/STORAGE:tooladm:ALL_TEAMS
hpx623:90:/mtruser3/enb/aim:mtrwrk32:ALL_TEAMS

 

Hi all,

 

This is my first post here and unfortunately,my beginning  starts with an issue :)

As you can see from above there is a file system checking script(that works with the second file which is the configuration file containing the servers to be checked) that checks the space availability in several Filesystems from different machines, most of them unix but one that runs Solaris and one that runs HP-UX B.11.31.

 

This script generates an email that contains the report of the FS availability.

The issue that I have is that even though the command df -h . works for all the other machines, it does not in the HP machine and the result I get is a messy email that does not even generate the space availability of the FS that the HP machine hosts. I saw different resolutions to this "problem" on the net but my question is how can I modify the existing script in order to get the same result from the HP machine as I do from the other UNIX/Linux/Sun machines.

I would be grateful if I get some help here because I am new to HP environment and to ksh scripting in general :)

2 REPLIES 2
Steven Schweda
Honored Contributor

Re: File System check script issue with HP

> [...] I saw different resolutions to this "problem" on the net [...]

   I hope that you realize how little useful information that statement
conveys.

> [...] my question is how can I modify the existing script in order to
> get the same result from the HP machine as I do from the other
> UNIX/Linux/Sun machines.

dyi# uname -a
HP-UX dyi B.11.31 U ia64 4235313755 unlimited-user license

dyi# df -h
df: illegal option -- h
usage : df [-F FStype] [-V] [-egiklnsvfb] [-t|-P] [-o specific_options]
           [special | directory ...]

   You might:

   Use a command other than "df -h" on your HP-UX systems?

   Install a better "df" program on your HP-UX systems, and use that?

      http://hpux.connect.org.uk/hppd/hpux/Gnu/coreutils-8.31/

As usual, many things are possible.


> I would be grateful if I get some help here because I am new to HP
> environment and to ksh scripting in general :)

   Get ready for an education.

Steven Schweda
Honored Contributor

Re: File System check script issue with HP

   I built mine from source (https://www.gnu.org/software/coreutils/),
instead of using that pre-built depot, but:

dyi# /usr/local/bin/df --version
df (GNU coreutils) 8.31
Copyright (C) 2019 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
<https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Torbjorn Granlund, David MacKenzie, and Paul Eggert.

dyi# /usr/local/bin/df -h
Filesystem       Size  Used Avail Use% Mounted on
/dev/vg00/lvol3  1.0G  324M  696M  32% /
/dev/vg00/lvol1  1.8G  283M  1.5G  16% /stand
/dev/vg00/lvol8  4.5G  1.3G  3.2G  29% /var
/dev/vg00/lvol7   46G   17G   30G  37% /usr
/dev/vg00/lvol4  512M   21M  488M   5% /tmp
/dev/vg00/lvol6  8.0G  4.9G  3.1G  62% /opt
/dev/vg00/lvol5  112M  5.7M  106M   6% /home
DevFS            3.0K  3.0K     0 100% /dev/deviceFileSystem

 
   After you have a better "df" installed on your HP-UX systems, all you
need to do is figure out how you would like to get your script to use
the better "df" on those systems (instead of the usual "/usr/bin/df").
There's more than one way to do that, too.