1833796 Members
4767 Online
110063 Solutions
New Discussion

Re: Extract data

 
juno2
Super Advisor

Extract data

Sorry to ask such simple question there , but I really want to have a suggestion.

I have a text mode program (run on unix shell)to monitor the db preformance , I would like to extract some data from this program, the program like these:

# dbmon ./ordb

DB MONITOR

Database: /usr/local/bin/db/ordb

1. System activities
2. Locking and Waiting Statistics


When I press "2" key , then go to the next screen

Locking and Waiting:

Type Usr Name Record Trans Schema
Lock 999 TOTAL... 254999 17 0
Wait 999 TOTAL... 0 0 0
Lock 0 root 0 0 0
Wait 0 root 0 0 0

What I want is to extract the data â Lock 999 TOTAL... 254999 17 0â .
My problem is I must manually press the â 2â key then to go to the next screen , I want the program can extract this data into a text file automatically and reqularly but no need to interactively to press any key , could suggest can can I do ?

I am not sure whether it is clear to understand , but I am very wellcome to answer if any point is
9 REPLIES 9
Graham Cameron_1
Honored Contributor

Re: Extract data

This might work - depends on how well behaved your ordb program is.
--
1. Create a text file containing the line "2", and another line with whatever command you need to run to quit your program. Call this file (say) TWO.
2. Run your program, piping input from TWO and output to another file, say "OUT", using
"./ordb OUT 2>/dev/null".
3. Extract the line(s) you want with grep, using "grep Lock OUT|grep TOTAL"
--
Hope that helps
-- Graham
Computers make it easier to do a lot of things, but most of the things they make it easier to do don't need to be done.
Mark Grant
Honored Contributor

Re: Extract data

Actually, you don't need to have a text file you can just echo the keypresses to get the data and exit into the pipe. Try,

echo "2" | dbmon ./ordb | grep Lock | grep Total

This assumes you don't heve to press enter after the "2" (if you do, then make it "2\n") and that you don't need to do any extra typing to exit the application.
Never preceed any demonstration with anything more predictive than "watch this"
RolandH
Honored Contributor

Re: Extract data

Write a wrapper around that programm.
Then it looks like this.

Call it ordbout.wrp

#/usr/bin/ksh

/usr/local/bin/db/ordb 2
EOF

That's it.

If you need more inputs to get more data or to quit programm you can put this input between the command call and the EOF. Each must be in a seperate line.

HTH
Roland
Sometimes you lose and sometimes the others win
Elmar P. Kolkman
Honored Contributor

Re: Extract data

In most cases you can do this using the following command:
echo 2 | dbmon ./ordb

For the extraction of the lines you need I would use grep.

Success
Every problem has at least one solution. Only some solutions are harder to find.
RolandH
Honored Contributor

Re: Extract data

Sorry,
your command must look like this


#/usr/bin/ksh

2
EOF

HTH
Roland
Sometimes you lose and sometimes the others win
juno2
Super Advisor

Re: Extract data

Thx all reply, I tried RolandH's method but I am not very clear ,

I used the script you provide , but pop the error :
./dbmon: line 3: EOF: No such file or directory
./dbmon: line 4: 2: command not found
./dbmon: line 5: EOF: command not found

Could suggest what is the problem ? thx.
Mark Grant
Honored Contributor

Re: Extract data

June, I think Rolad made a typo, it should be

<< EOF
Never preceed any demonstration with anything more predictive than "watch this"
juno2
Super Advisor

Re: Extract data

Thx reply, it is Ok now , I can get the text file , but there is a another problem ,

In the report , there are over 50 lines , but if I use Mark's method , it will export the first page to the output , is it passible to export all 50 lines to the report ? thx.

Locking and Waiting:

Type Usr Name Record Trans Schema
Lock 999 TOTAL... 254999 17 0
Wait 999 TOTAL... 0 0 0
Lock 0 root 0 0 0
Wait 0 root 0 0 0
..
..
..
..
..
..
.
juno2
Super Advisor

Re: Extract data

In my dbmon program , it need to press "Enter" key to change to next screen , how can I add the "Enter" to the file ? thx.