?
Solved

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

Posted on 2003-03-12
11
Medium Priority
?
721 Views
Last Modified: 2007-12-19
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
Comment
Question by:issa7860
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 4
11 Comments
 

Accepted Solution

by:
kilman earned 100 total points
ID: 8128462
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
 

Author Comment

by:issa7860
ID: 8128769
Kilman,

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

Thanks.
0
 

Author Comment

by:issa7860
ID: 8128880
Kilman,

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

Thanks.
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 

Author Comment

by:issa7860
ID: 8128980
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
 

Expert Comment

by:kilman
ID: 8129244
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
 

Author Comment

by:issa7860
ID: 8130352
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
 

Author Comment

by:issa7860
ID: 8132644
anyboby have any idea on this problem???
0
 

Expert Comment

by:kilman
ID: 8135145
Issa,
Sorry I had a semi-comma after the fi statement.
Please remove and retry

Kil
0
 

Author Comment

by:issa7860
ID: 8140047
I removed the ; and % sign from the script but stll getting the same error  ksh: [21:  not found.

Can someone help?
0
 

Expert Comment

by:kilman
ID: 8165138
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
 

Author Comment

by:issa7860
ID: 8168685
Thanks to all! I have figured out the problem.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
Via a live example, show how to take different types of Oracle backups using RMAN.
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question