• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 733
  • Last Modified:

Reading a unix flat file and mailing when PCTUSED is greater than 50%

Hello,

I am trying to write a shell script that reads the unix flat file and email me those lines only when PCT_USED is greater than 50% and I got stuck. Can anyone please help me ASAP. Thanks in advance!

The flat file format looks like this:

HOSTNAME
FILESYSTEM ALLOCATED USED FREE PCTUSED MOUNTON

and the following is the script that I started out before I got stuck:

#!/bin/ksh                                                                      
                                                             
cat unix flat file |while read record              
do                                                                              
num_col=`echo $record|wc -w`                                                  
if [ $num_col -eq 1 ];                                                        
then                                                                          
   HOSTNAME=${record}                                                          
echo $HOSTNAME                                                                  
else                                                                          
   if  [ -n $record ];                                                        
   then                                                                        
     echo $record|read FILESYSTEM ALLOCATED USED FREE PCTUSED MOUNTON    
fi
fi
done      
The script works fine upto here and reads the values but then where I go from here, how do you give the condition: [if $PCTUSED -gt 50] then mailx $hostname, $filesystem,$allocated,$used,$free,$pctused,$mounton

Any help is appreciated!    
0
issa7860
Asked:
issa7860
  • 7
  • 4
1 Solution
 
kilmanCommented:
Issa,
Heres what you need

if [ $PCTUSED -gt 50 ] ; then
echo $HOSTNAME $FILESYSTEM $ALLOCATED $USED $FREE $PCTUSED $MOUNTON | mailx -s "Subject" your@emailaddress.com ;
fi;

Good Luck

Kil
0
 
issa7860Author Commented:
Kilman,

Do I need to add your script at the end of my script??
where should I plug in?

Thanks.
0
 
issa7860Author Commented:
Kilman,

Do I need to add your script at the end of my script??
where should I plug in?

Thanks.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
issa7860Author Commented:
When I plug your script at the end of my script's last statement DONE then I get the following error:

ksh: 21%: 0403-053 Expression is not complete; more tokens expected.

Please help!
0
 
kilmanCommented:
issa,
yes at the end of the line.
Make sure that the email address is on the same line as the mailx command as this could be causing the problems.
0
 
issa7860Author Commented:
kilman,
I plugged your script after the last line in my script which is a DONE statement and I still received the following error: ksh: [21%:  not found.

any idea?? am I putting in the right place??
0
 
issa7860Author Commented:
anyboby have any idea on this problem???
0
 
kilmanCommented:
Issa,
Sorry I had a semi-comma after the fi statement.
Please remove and retry

Kil
0
 
issa7860Author Commented:
I removed the ; and % sign from the script but stll getting the same error  ksh: [21:  not found.

Can someone help?
0
 
kilmanCommented:
Issa,
Can you place the script here exactly as it is.
The originally script does not appear to have a % sign in it, so I'm wondering where you removed it from

Kil
0
 
issa7860Author Commented:
Thanks to all! I have figured out the problem.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 7
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now