- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Where to keep 'for loop' in given script ?
Operating System - HP-UX
1748209
Members
2723
Online
108759
Solutions
Forums
Categories
Company
Local Language
юдл
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
юдл
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-03-2010 06:57 PM
тАО12-03-2010 06:57 PM
# /usr/local/bin/sh
. /usr/local/bin/oraenv_DVEC6FIN
Declare
expected_count=50
current_count=`echo "psc" | tmadmin 2>/dev/null | grep ASYNCDECISI | wc -l`
if [ $current_count -lt $expected_count ]
then
echo alert > alert.log
fi
prev_count=$current_count
while [ 1 ]
do
current_count=`echo "psc" | tmadmin 2>/dev/null | grep ASYNCDECISI | wc -l`
if [ $current_count -lt $prev_count ] && [ $current_count -lt $expected_count ]
then
echo alert > alert.log
fi
if [ $prev_count -ne $current_count ]
then
prev_count=$current_count
fi
sleep 5
done
_______________________________________________
The above script is perfectly working (infinite) script. In which I wanted to include below for loop.
so that I can reduce number of scripts.
I tried keeping for loop after above while statement which didnt work. Pelase advice where I can keep this for for loop staement in the above scritp.
_______________________________________________
#Monitor count 12 services
SERVICE12="CANCELAPPLI FULLBATCHAPP GETBATCHDEC GETMULTIROWS OPTPAPERTCS PERSONALPRI TERMSIGNED"
for i in ${SERVICE12}
do
current_count=$(echo "psc" | tmadmin 2>/dev/null | grep -s -c ${i})
done
. /usr/local/bin/oraenv_DVEC6FIN
Declare
expected_count=50
current_count=`echo "psc" | tmadmin 2>/dev/null | grep ASYNCDECISI | wc -l`
if [ $current_count -lt $expected_count ]
then
echo alert > alert.log
fi
prev_count=$current_count
while [ 1 ]
do
current_count=`echo "psc" | tmadmin 2>/dev/null | grep ASYNCDECISI | wc -l`
if [ $current_count -lt $prev_count ] && [ $current_count -lt $expected_count ]
then
echo alert > alert.log
fi
if [ $prev_count -ne $current_count ]
then
prev_count=$current_count
fi
sleep 5
done
_______________________________________________
The above script is perfectly working (infinite) script. In which I wanted to include below for loop.
so that I can reduce number of scripts.
I tried keeping for loop after above while statement which didnt work. Pelase advice where I can keep this for for loop staement in the above scritp.
_______________________________________________
#Monitor count 12 services
SERVICE12="CANCELAPPLI FULLBATCHAPP GETBATCHDEC GETMULTIROWS OPTPAPERTCS PERSONALPRI TERMSIGNED"
for i in ${SERVICE12}
do
current_count=$(echo "psc" | tmadmin 2>/dev/null | grep -s -c ${i})
done
Solved! Go to Solution.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-03-2010 11:02 PM
тАО12-03-2010 11:02 PM
Re: Where to keep 'for loop' in given script ?
Is there a different expected count for each service?
The logic could be:
Initialize
Establish intial coutn for each service
While true;
for x y z ; do
get count
compare count to previous count
if conditions aren't favorable, log message
set previous to this
done
delay
done
The logic could be:
Initialize
Establish intial coutn for each service
While true;
for x y z ; do
get count
compare count to previous count
if conditions aren't favorable, log message
set previous to this
done
delay
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-04-2010 06:05 AM
тАО12-04-2010 06:05 AM
Re: Where to keep 'for loop' in given script ?
Hi:
It would seem that you want to include the same logic for the "SERVICE12" list as you do for "ASYNCDECISI". If that's correct, I would declare your 'count' variables as arrays to match their elements with the list of "services' (including ASYNCDECISI).
The syntax:
# current_count=$(echo "psc" | tmadmin 2>/dev/null | grep -s -c ${i})
...is the modern syntax to replace archaic backticks like:
# current_count=`echo "psc" | tmadmin 2>/dev/null | grep ASYNCDECISI | wc -l`
Equally important, the first variation eliminates an extra process of 'wc' since 'grep' can return a count of matches it finds (as shown). Thus for two reasons, the first variation is far preferable to the second.
There is no sense to doing:
if [ $prev_count -ne $current_count ]
then
prev_count=$current_count
fi
...Simply do:
prev_count=$current_count
Thus, in all, you might do:
while [ 1 ]
do
set -A current_count 0 0 0 0 0 0 0 0
set -A prev_count 0 0 0 0 0 0 0 0
which=0
SERVICE12="ASYNCDECISI CANCELAPPLI FULLBATCHAPP GETBATCHDEC GETMULTIROWS OPTPAPERTCS PERSONALPRI TERMSIGNED"
for i in ${SERVICE12}
do
which=$((which+1))
current_count[$which]=$(echo "psc" | tmadmin 2>/dev/null | grep -s -c ${i})
...
done # with for loop
sleep 5
done # with while loop
...
Regards!
...JRF...
It would seem that you want to include the same logic for the "SERVICE12" list as you do for "ASYNCDECISI". If that's correct, I would declare your 'count' variables as arrays to match their elements with the list of "services' (including ASYNCDECISI).
The syntax:
# current_count=$(echo "psc" | tmadmin 2>/dev/null | grep -s -c ${i})
...is the modern syntax to replace archaic backticks like:
# current_count=`echo "psc" | tmadmin 2>/dev/null | grep ASYNCDECISI | wc -l`
Equally important, the first variation eliminates an extra process of 'wc' since 'grep' can return a count of matches it finds (as shown). Thus for two reasons, the first variation is far preferable to the second.
There is no sense to doing:
if [ $prev_count -ne $current_count ]
then
prev_count=$current_count
fi
...Simply do:
prev_count=$current_count
Thus, in all, you might do:
while [ 1 ]
do
set -A current_count 0 0 0 0 0 0 0 0
set -A prev_count 0 0 0 0 0 0 0 0
which=0
SERVICE12="ASYNCDECISI CANCELAPPLI FULLBATCHAPP GETBATCHDEC GETMULTIROWS OPTPAPERTCS PERSONALPRI TERMSIGNED"
for i in ${SERVICE12}
do
which=$((which+1))
current_count[$which]=$(echo "psc" | tmadmin 2>/dev/null | grep -s -c ${i})
...
done # with for loop
sleep 5
done # with while loop
...
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-04-2010 06:29 AM
тАО12-04-2010 06:29 AM
Solution
Hi (again):
There's an obvious, silly mistake in the code snippet I suggested. We certainly don't want to initialize the count arrays every time. I meant to write:
...
set -A current_count 0 0 0 0 0 0 0 0
set -A prev_count 0 0 0 0 0 0 0 0
SERVICE12="ASYNCDECISI CANCELAPPLI FULLBATCHAPP GETBATCHDEC GETMULTIROWS OPTPAPERTCS PERSONALPRI TERMSIGNED"
while [ 1 ]
do
which=0
for i in ${SERVICE12}
do
which=$((which+1))
current_count[$which]=$(echo "psc" | tmadmin 2>/dev/null | grep -s -c ${i})
...
done # with for loop
sleep 5
done # with while loop
Regards!
...JRF...
There's an obvious, silly mistake in the code snippet I suggested. We certainly don't want to initialize the count arrays every time. I meant to write:
...
set -A current_count 0 0 0 0 0 0 0 0
set -A prev_count 0 0 0 0 0 0 0 0
SERVICE12="ASYNCDECISI CANCELAPPLI FULLBATCHAPP GETBATCHDEC GETMULTIROWS OPTPAPERTCS PERSONALPRI TERMSIGNED"
while [ 1 ]
do
which=0
for i in ${SERVICE12}
do
which=$((which+1))
current_count[$which]=$(echo "psc" | tmadmin 2>/dev/null | grep -s -c ${i})
...
done # with for loop
sleep 5
done # with while loop
Regards!
...JRF...
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP