Print available running instance out of total


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Print available running instance out of total
# 1  
Old 08-15-2010
Print available running instance out of total

Hello.
I have a status command in AIX box, which provides output as below:

Code:
$ status

You are running the application on pegasus2

----Program Name------|--Avail / Total---------|
 MQ                   |          1/2           |
 ORACLE               |         10/10          |
 TMADMIN              |          2/2           |
 ------------------   |   -------------------  |

I am seeking to write a script with output: How many Objects are available out of Total i.e.
1 MQ Running Out of 2
10 ORACLE Running Out of 10
2 TMADMIN Running Out of 2

I started preparing something like:
Code:
status | while read n
do
avail=`echo ${n} | awk -F " " '{print $1}'`
done

Your help will be appreciated for completing this. Thank you.

Last edited by Scott; 08-16-2010 at 02:17 AM.. Reason: Please use code tags
# 2  
Old 08-15-2010
Code:
status |awk -F \| ' !/^-/&&/\// {split($2,a,"/"); print a[1],$1," Running Out of ", a[2]}'

# 3  
Old 08-16-2010
Thank you very much. It is awesome.

Can you please explain the meanings of !/^-/&&/\// {split($2,a,"/"); print a[1],$1," Running Out of ", a[2]}

---------- Post updated at 03:37 PM ---------- Previous update was at 03:13 PM ----------

Also, If I want to compare a[1] and a[2]. How do I do that? i.e. If a[1] is < a[2] echo 'error'
# 4  
Old 08-16-2010
Code:
!/^-/&&/\//    # only take the line with / but not the head and tail.
{split($2,a,"/");    # split second column with / and save in array a, for example the first record will be a[1]=1, a[2]=2
print a[1],$1," Running Out of ", a[2]}      # print the output according your expect format.

Code:
status|awk -F \| ' !/^-/&&/\// {split($2,a,"/"); print (a[1]<=a[2])?a[1] " " $1 " Running Out of " a[2]:$1 " error"}'


Last edited by rdcwayx; 08-16-2010 at 02:48 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Making sure only one instance of a script is running

so i have a script that takes a while to complete and its cpu intensive. this script is being used by several users. i want to make sure only 1 user can run this script at any given time. i originally thought of running a while loop to egrep the process table of the PID ($$) of the process,... (7 Replies)
Discussion started by: SkySmart
7 Replies

2. UNIX for Advanced & Expert Users

How to check a single process instance is always running?

Hi, I want to write one program in C in Unix OS which will check the running status of a process time to time. If the process is stopped somehow by any means, it will ensure that the process is restarted and only one copy of the process image should run in memory at any point of time for the user.... (2 Replies)
Discussion started by: sanzee007
2 Replies

3. Shell Programming and Scripting

sed command to print first instance of pattern in range

The following text is in testFile.txt: one 5 two 10 three 15 four 20 five 25 six 10 seven 35 eight 10 nine 45 ten 50 I'd like to use sed to print the first occurance of search pattern /10/ in a given range. This command is to be run against large log files, so to optimize efficiency,... (9 Replies)
Discussion started by: uschaafm
9 Replies

4. Shell Programming and Scripting

Process Instance not running properly.

I have run 10 instances of the process eg, process name is BG nohup /WP01IRB1_irbapp/IRBWPROD/RB/bin/BG -c 1 -t 23 -a '-caTop TESTBILLCYCLE='5FEB13_81PT19NPT''>a.txt & nohup /WP01IRB1_irbapp/IRBWPROD/RB/bin/BG -c 2 -t 23 -a '-caTop TESTBILLCYCLE='5FEB13_81PT19NPT''>b.txt & nohup... (3 Replies)
Discussion started by: ankitknit
3 Replies

5. Shell Programming and Scripting

How to restrict running one instance of scp at any time in fsniper

How to restrict running one instance of scp at any time? (2 Replies)
Discussion started by: proactiveaditya
2 Replies

6. Shell Programming and Scripting

Running Total Running Wild

Hi. A shell scripting newbie here. I am trying to write a script that will create a running total of Sales, and increment a counter for each Sales entry, but when I executed the program it never stopped. counter=0 Sales=0 echo "enter sales price" read sales while do let counter=counter+1... (6 Replies)
Discussion started by: Ccccc
6 Replies

7. Shell Programming and Scripting

[PHP] endless loop mimics a cron. Make sure only one instance is running

Hi, PHP user here. I'm using an endless loop to perform to mimic a cron. The script does something every 20 minutes. It sleep()s in the meantime. I have various checks that ensure that only instance can run, including a "gentleman agreement" locked file. However, I'd like to make sure... (2 Replies)
Discussion started by: jjshell
2 Replies

8. Shell Programming and Scripting

Running Total

HPUX 11i v2 #!/bin/sh Hi all. I have a space delimited flat file of about 9000 lines. I would like to get a running total of field 3 to the variable $TOTAL. Field 3 can be formatted as listed.... $ 0.00 $2804.15 <$ 4.14> (negative) Any ideas are most appreciated!!!! TIA!! (9 Replies)
Discussion started by: lyoncc
9 Replies

9. UNIX for Dummies Questions & Answers

grep running total/ final total across multiple files

Ok, another fun hiccup in my UNIX learning curve. I am trying to count the number of occurrences of an IP address across multiple files named example.hits. I can extract the number of occurrences from the files individually but when you use grep -c with multiple files you get the output similar to... (5 Replies)
Discussion started by: MrAd
5 Replies

10. Shell Programming and Scripting

How to check if another instance of the process is running

Hi, I am writing a shell script to invoke a C++ program. Before I start the C++ program (oi7loadbalancer), I am checking if the process is already running. I start the process only if it is not already running. I have the following check in my script. proccount=`ps -f -u $USER_NAME | grep... (8 Replies)
Discussion started by: sim
8 Replies
Login or Register to Ask a Question