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

#!/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

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..:b::):):slight_smile:

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

use nawk in Solaris

#!/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)
        }

} '

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

you have not read my reply's first sentence.

thanks buddy its workin now sorry for not reading the message properly..:slight_smile:

'swap' command is not working in Suse Linux 9.What is the equivalent command?

Regards
Dileep Pattayath

the free command

Working.Thanks for your reply