If Condition usage.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting If Condition usage.
# 1  
Old 01-25-2012
If Condition usage.

Hi,

I have a script to take the count of tansaction in all blades. The same works perfectly Fine. The out put of the same is as below.

[xmp@tswebpxmpadmin siddhesh]$ ./curtps_stg.sh tcp |grep Trans
tswebpxmp6 00:45h Transparent TPS: 409
tswebpxmp7 00:45h Transparent TPS: 425
tswebpxmp8 00:45h Transparent TPS: 439
tswebpxmp9 00:45h Transparent TPS: 271
tswebpxmp10 00:45h Transparent TPS: 403
tswebpxmp11 00:45h Transparent TPS: 413
tswebpxmp12 00:45h Transparent TPS: 407
tswebpxmp13 00:45h Transparent TPS: 440
tswebpxmp14 00:45h Transparent TPS: 437
tswebpxmp15 00:45h Transparent TPS: 400
tswebpxmp16 00:45h Transparent TPS: 428


[xmp@tswebpxmpadmin siddhesh]$ ./curtps_stg.sh proxy |grep Proxy
tswebpxmp3 00:45h Proxy TPS: 188
tswebpxmp4 00:45h Proxy TPS: 178
tswebpxmp5 00:45h Proxy TPS: 191


I wish to write a script to alert if tps counts reach low (=<200) and high (>=900) level/count (per server) wherein the level can be manually be changed.

Please advice.

-Siddhesh.K

---------- Post updated at 10:20 PM ---------- Previous update was at 10:19 PM ----------

Original script is as follows.

Code:
location_prefix=tswebp
mgt_ip1=10.219.3.129
mgt_ip2=10.219.3.130

totalonly=0
individual=0

if [ $# -gt 0 ]
then
        if [ "$1" = "-t"  -o "$1" = "Starhub" ]
        then
                totalonly=1
        elif [  "$1" = "proxy" ]
        then
                . /home/xmp/bin/ALLBLADES
                blades=$proxyblades
                individual=1
        elif [  "$1" = "tcp" ]
        then
                . /home/xmp/bin/ALLBLADES
                blades=$tcpblades
                individual=1
        elif [  "$1" = "all" ]
        then
                . /home/xmp/bin/ALLBLADES
                individual=1
        else
                blades="$*"
                individual=1
        fi
fi

if [ $individual -eq 1 ]
then
        for blade in $blades
        do
                blade=`echo $blade | sed -e s/$location_prefix//`
                TPS=0
                TTPS=0
                PTPS=0
                WTPS=0
                RSTRT=0
                RSTOP=0
                tmpnam=/tmp/$blade.btps.$$
                statcli -s -n LOGGER.${location_prefix}$blade/CCS/.* > $tmpnam 2> /dev/null
                rc=`cat $tmpnam | wc -l`
                if [ $rc -gt 1 ]
                then
                        TPS=`cat $tmpnam | sed -e '1,14d' -e '16,$d' | sed -e 's/^.* .* //' 2> /dev/null`
                        TTPS=`cat $tmpnam | sed -e '1,50d' -e '52,$d' | sed -e 's/^.* .* //' 2> /dev/null`
                        PTPS=`cat $tmpnam | sed -e '1,26d' -e '28,$d' | sed -e 's/^.* .* //' 2> /dev/null`
                        WTPS=`cat $tmpnam | sed -e '1,74d' -e '76,$d' | sed -e 's/^.* .* //' 2> /dev/null`
                        RSTRT=`cat $tmpnam | sed -e '1,122d' -e '124,$d' | sed -e 's/^.* .* //' 2> /dev/null`
                        RSTOP=`cat $tmpnam | sed -e '1,128d' -e '130,$d' | sed -e 's/^.* .* //' 2> /dev/null`
                fi
                rm -f $tmpnam
                echo "${location_prefix}$blade" "`date +'%H:%Mh        Total TPS: '`" $TPS
                echo "${location_prefix}$blade"  "`date +'%H:%Mh  Transparent TPS: '`" $TTPS
                echo "${location_prefix}$blade"  "`date +'%H:%Mh        Proxy TPS: '`" $PTPS
                echo "${location_prefix}$blade"  "`date +'%H:%Mh         WAP1 TPS: '`" $WTPS
                echo "${location_prefix}$blade"  "`date +'%H:%Mh Radius Start/sec: '`" $RSTRT
                echo "${location_prefix}$blade"  "`date +'%H:%Mh Radius Stopp/sec: '`" $RSTOP
        done
        exit 0
fi

cmu -c -d RESOURCE-MONITOR.${location_prefix}xmp1 | grep CEECFG_PgrmRole | grep FTP > /dev/null 2>&1
rc=$?
if [ $rc -eq 0 ]
then
        primary_ip=$mgt_ip1
else
        primary_ip=$mgt_ip2
fi

TPS=`on tswebpxmp1 snmpget -c public -v 2c $primary_ip:1610  1.3.6.1.4.1.12702.9.2.6.2.0 | grep Counter64 | sed -e's;^.*Counter64: ;;'`
echo "`date +'%H:%Mh        Total TPS: '`" $TPS
if [ $totalonly -ne 1 ]
then
        PTPS=`on tswebpxmp1 snmpget -c public -v 2c 127.0.0.1:1610  1.3.6.1.4.1.12702.9.2.3.2.0 | grep Counter64 | sed -e's;^.*Counter64: ;;'`
        TTPS=`on tswebpxmp1 snmpget -c public -v 2c 127.0.0.1:1610  1.3.6.1.4.1.12702.9.2.8.2.0 | grep Counter64 | sed -e's;^.*Counter64: ;;'`
        WTPS=`on tswebpxmp1 snmpget -c public -v 2c 127.0.0.1:1610  1.3.6.1.4.1.12702.9.2.14.2.0 | grep Counter64 | sed -e's;^.*Counter64: ;;'`
        RSTRT=`on tswebpxmp1 snmpget -c public -v 2c 127.0.0.1:1610  1.3.6.1.4.1.12702.9.2.11.2.0 | grep Counter64 | sed -e's;^.*Counter64: ;;'`
        RSTOP=`on tswebpxmp1 snmpget -c public -v 2c 127.0.0.1:1610  1.3.6.1.4.1.12702.9.2.12.2.0 | grep Counter64 | sed -e's;^.*Counter64: ;;'`
        echo "`date +'%H:%Mh  Transparent TPS: '`" $TTPS
        echo "`date +'%H:%Mh        Proxy TPS: '`" $PTPS
        echo "`date +'%H:%Mh         WAP1 TPS: '`" $WTPS
        echo "`date +'%H:%Mh Radius Start/sec: '`" $RSTRT
        echo "`date +'%H:%Mh Radius Stopp/sec: '`" $RSTOP
fi

Moderator's Comments:
Mod Comment Please use next time code tags for ALL your code and data...

Last edited by vbe; 01-25-2012 at 01:00 PM..
# 2  
Old 01-25-2012
Code:
#!/bin/ksh
# warn on <=200 and >=900

var=$(awk '/Trans/ || /Proxy/ && $(NF)>=900 || $(NF)<=200' \
   <(./curtps_stg.sh tcp |grep Trans) <( ./curtps_stg.sh proxy |grep Proxy) )

if [ ! -z "$var" ] ; then
   echo "$var" | mailx -s 'Warning' you@yourcompany.com
fi

All of those cat usages and using children to do work to populate every variable are not efficient. If your input file becomes huge that script will run for an unecessarily long time.
# 3  
Old 01-31-2012
Hello,

Thanks for the reply, i tried executing the same,but it gives below mentioned error.

Code:
 ./curtps_new.sh
awk: cmd. line:1: fatal: cannot open file ` /dev/fd/63' for reading (No such file or directory)

Please advice.
-Siddhesh.K
# 4  
Old 01-31-2012
Quote:
Originally Posted by jim mcnamara
Code:
#!/bin/ksh
# warn on <=200 and >=900
 
var=$(awk '/Trans/ || /Proxy/ && $(NF)>=900 || $(NF)<=200' \
   <(./curtps_stg.sh tcp |grep Trans) <( ./curtps_stg.sh proxy |grep Proxy) )
 
if [ ! -z "$var" ] ; then
   echo "$var" | mailx -s 'Warning' you@yourcompany.com
fi

All of those cat usages and using children to do work to populate every variable are not efficient. If your input file becomes huge that script will run for an unecessarily long time.

Actually passing output of two commands as input to AWK is not recommended. Since there can be only one input STDIN, hence we can try something like this:

Code:
#!/bin/ksh
# warn on <=200 and >=900
 
var=$(awk '/Trans/ || /Proxy/ && $(NF)>=900 || $(NF)<=200' \
   <(./curtps_stg.sh tcp |grep Trans ;  ./curtps_stg.sh proxy |grep Proxy) )
 
if [ ! -z "$var" ] ; then
   echo "$var" | mailx -s 'Warning' you@yourcompany.com
fi

# 5  
Old 01-31-2012
Hello,

I tried doing the mentioned changes. still there is a error.

Code:
$ ./curtps_new.sh
awk: cmd. line:1: fatal: cannot open file ` ' for reading (No such file or directory)
./curtps_new.sh: line 5: /dev/fd/63: Permission denied

i am executing the script with a normal user and not with root. the mentioned "./curtps_stg.sh tcp |grep Trans" script runs with this user.

Also my code for your reference
Code:
#!/bin/bash

var=$(awk '/Trans/ || /Proxy/ && $(NF)>=500 || $(NF)<=200' \
  <(./curtps_stg.sh tcp |grep Trans ;  ./curtps_stg.sh proxy |grep Proxy) )

if [ ! -z "$var" ] ; then
#   echo "$var" | mailx -s 'Warning' you@yourcompany.com
   echo "$var"
fi

exit 0

Please advice.

-Siddhesh.K
# 6  
Old 01-31-2012
I am having BASH and not KSH right now, so can't test the same on KSH. But ideally it should have worked.


So for now, lets just break the input commands into two:


Code:
 
#!/bin/bash
 
var1=$(awk '/Transparent/ && $(NF)>=500 || $(NF)<=200' \
<(./curtps_stg.sh tcp |grep Trans))
 
var2=$(awk '/Proxy/ && $(NF)>=500 || $(NF)<=200' \
<(./curtps_stg.sh proxy |grep Proxy) )
 
if [[ ! -z "${var1}" || ! -z "${var2}" ]] ; then
# echo "$var" | mailx -s 'Warning' you@yourcompany.com
echo "${var1} or ${var2}"
fi
 
exit 0


Last edited by knight_eon; 01-31-2012 at 03:22 AM.. Reason: Applied appropriate tags
# 7  
Old 01-31-2012
Thanks a lot.

That worked like magic.

Siddhesh.K
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Memory usage per user,percent usage,sytem time in ksh

Let's say i have 20 users logged on Server. How can I know how much memory percent used each of them is using with system time in each user? (2 Replies)
Discussion started by: roy1912
2 Replies

2. Shell Programming and Scripting

If condition return 0 even when it fails to satisfy te condition

HI My doubt may be basic one but I need to get it clarified.. When i use "if" condition that checks for many AND, OR logical conditions like if ]; then return 0 fi Even the if condition fails it returns as zero.. Any clue.. But if i add else condition like if ]; ... (2 Replies)
Discussion started by: Priya Amaresh
2 Replies

3. Shell Programming and Scripting

redirect stdout echo command in condition A run in condition B

hi, I have some problems in my simple script about the redirect echo stdout command inside a condition. Why is the echo command inside the elif still execute in the else command Here are my simple script After check on the two diff output the echo stdout redirect is present in two diff... (3 Replies)
Discussion started by: jao_madn
3 Replies

4. HP-UX

Difference between [condition] and [[condition]] and ((condition)) when used with if condition

Executed the following if conditions .. and got different results . only (( )) gave correct o/p with all scenarios . Can anybody please let me know what is the difference between and ] and ((condition)) when used with if condition. And why each condition gave different result. 1.... (2 Replies)
Discussion started by: soumyabubun
2 Replies

5. UNIX for Dummies Questions & Answers

Command to display the space usage (memory usage) of a specific directory.

Hi all, Can you please tell me the command, with which one can know the amount of space a specific directory has used. df -k . ---> Displays, the amount of space allocated, and used for a directory. du -k <dir name> - gives me the memory used of all the files inside <dir> But i... (2 Replies)
Discussion started by: abhisheksunkari
2 Replies

6. Shell Programming and Scripting

Confused with the usage of one variable usage

Hi All I am not able to understand the usage of d# in the below variable declaration. FILE_LOC contains the directory path And also help me to know about what will be saved in the variable j. Thanks!!! j=${d#${FILE_LOC}/} (2 Replies)
Discussion started by: mohanm
2 Replies

7. AIX

How to monitor the IBM AIX server for I/O usage,memory usage,CPU usage,network..?

How to monitor the IBM AIX server for I/O usage, memory usage, CPU usage, network usage, storage usage? (3 Replies)
Discussion started by: laknar
3 Replies

8. Solaris

current CPU usage, memory usage, disk I/O oid(snmp)

Hi, I want to monitor the current cpu usage, monitor usage , disk I/o and network utlization for solaris using SNMP. I want the oids for above tasks. can you please tell me that Thank you (2 Replies)
Discussion started by: S_venkatesh
2 Replies

9. HP-UX

how can I find cpu usage memory usage swap usage and logical volume usage

how can I find cpu usage memory usage swap usage and I want to know CPU usage above X% and contiue Y times and memory usage above X % and contiue Y times my final destination is monitor process logical volume usage above X % and number of Logical voluage above can I not to... (3 Replies)
Discussion started by: alert0919
3 Replies

10. Programming

Monitor CPU usage and Memory Usage

how can i monitor usages of CPU, Memory, Hard disk etc. under SUN Solaries through a c program or java program i want to store that data into database so i can show it graphically thanks in advance (2 Replies)
Discussion started by: Gajanad Bihani
2 Replies
Login or Register to Ask a Question