The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
ksh scripting help praveenbvarrier Shell Programming and Scripting 1 04-15-2008 07:19 AM
sql scripting help sam786 Shell Programming and Scripting 3 12-10-2007 09:31 AM
difference between AIX shell scripting and Unix shell scripting. haroonec Shell Programming and Scripting 2 04-12-2006 05:12 AM
scripting guru's pls help me with scripting on AIX thatiprashant Shell Programming and Scripting 1 01-20-2006 04:58 PM
Scripting? woofie What's on Your Mind? 1 03-09-2005 04:03 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 01-14-2008
Registered User
 

Join Date: Sep 2006
Posts: 17
Smile Need help in scripting

Hi i need some help of u big guys who is expert in scripting ..! I want a script that check the swap space every 10/15 sec and if it finds swap being utilised to 80%, should raise an alert to the root..! any one of you if can put some light on this i will be very glad ..? looking for some positive replies
Reply With Quote
Forum Sponsor
  #2  
Old 01-14-2008
Tytalus's Avatar
Registered User
 

Join Date: Jun 2003
Location: Scotland
Posts: 290
Code:
#!/bin/sh
while true
do
sleep 15
x=`swap -s | sed 's/k//g' | awk '{print ( $9 * 100 )/( $9 + $11 )}'`
if [ $x -gt 80 ];
  then echo "SWAP at $x" | mailx -s 'SWAP ALERT' root
fi
done

should work
Reply With Quote
  #3  
Old 01-14-2008
Registered User
 

Join Date: Sep 2006
Posts: 17
reply

Thanks for your time and effort I need to check this work and let u know, but its quite diffcult to understand the script , i need to learn more on it can u tell me this site i can get better document to under this ...??? But anywaz thanks for your script..
Reply With Quote
  #4  
Old 01-15-2008
Registered User
 

Join Date: Sep 2006
Posts: 17
need help again

Hi Tytalus,

thanks its working ..i tried tht but need some more of ur help I need to add few more line to get the total no of process running "echo no of process" and one process say proces x if ecxeed no of process say 4 shoould also be shown in the same mail..

i try out some my junk scripting technique please check and verify also edit the same if it is wrong

#!/bin/sh
while true
do
sleep 15
x=`swap -s | sed 's/k//g' | awk '{print ( $9 * 100 )/( $9 + $11 )}'`
if [ $x -gt 40 ] && [ $x > 40 ];
then echo "SWAP at $x
do

y='ps -ef|wc -l
echo "No of process $y
c= pgrep rational | wc -l
if [$c > 4 ]|mailx -s SWAP ALERT -very high root


fi
done

please dont lauge at my poor skill in scripting but appriceate my spirit in scripting, and help me getting this script done..


thanking you in advance..
Reply With Quote
  #5  
Old 01-15-2008
Registered User
 

Join Date: Sep 2006
Posts: 1,580
use nawk in Solaris
Code:
#!/bin/sh
ps -ef | awk 'BEGIN{
        cmd="swap -s"
        cmd | getline line
        close(cmd)
        split(line,array)
        percent = (array[9]/(array[9]+array[11])) * 100
}

END{
        if ( percent > 40) {
                email="mailx -s \047subject\047 root"
                s= s "Number of processes : "NR"\n"
                s= s "Swap at " percent
                print s | email
                close(email)
        }

} '
Reply With Quote
  #6  
Old 01-15-2008
Registered User
 

Join Date: Sep 2006
Posts: 17
Smile Reply to ghostgog74

Hi ghostdog,


i try to run the script but getting some error in line 3 and line 11 , well just check this script i just done its giving error "unexpected end of line done" ,if possible please fix it..

#!/bin/sh
while true
do
sleep 15
y='ps -ef |wc -l
then echo "No of Process at $y" >> swap.alert
z='pgrep rational| wc -l | sed s/k//g' /awk '{print ($8)}'
if [ $z > 4 ];
then echo "Rational process at $z" >> swap.alert
x=`swap -s | sed 's/k//g' | awk '{print ( $9 * 100 )/( $9 + $11 )}'`
if [ $x -gt 80 ];
then echo "SWAP at $x" >> swap.alert | cat swap.alert |mailx -s 'SWAP ALERT' root
fi
done
Reply With Quote
  #7  
Old 01-16-2008
Registered User
 

Join Date: Sep 2006
Posts: 1,580
Quote:
Originally Posted by nicknihal View Post
i try to run the script but getting some error in line 3 and line 11
you have not read my reply's first sentence.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
linux

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 07:26 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0