LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Help with script to capture the performance (https://www.linuxquestions.org/questions/linux-newbie-8/help-with-script-to-capture-the-performance-735060/)

katkota 06-23-2009 02:24 PM

Help with script to capture the performance
 
Folks;
i have a tool to check on some files, this tool runs using command line. when we run the tool on any file, it suppose to give you the file information to see if the file was digested into the system.
for example: if i have a file called "test.gz", when i run the tool which called "chktool" i do it like this:

# /opt/dev/chktool -getstat /home/test.gz

i normally get results looks like this:
Type F
Path /home/test.gz
Handle F431B8828E6D04
Mode 0766
UID 60000
GID 65534
Size 11706980
NAME test.gz
STAT CHEK
UID B0514B7A-D20E

then when the file is digested, and i run the same tool i got this result below (note the STAT changed from CHEK to ONLN)

Type F
Path /home/test.gz
Handle F431B8828E6D04
Mode 0766
UID 60000
GID 65534
Size 11706980
NAME test.gz
STAT ONLN
UID B0514B7A-D20E

I'm looking to write a script to capture the time when starting to ingest the file then keep running the tool until the status changes from CHEK to ONLN, once it's ONLN then check the time so i can see how long it took for this file to go from CHEK to ONLN.

Thanks in advance

Tinkster 06-23-2009 03:13 PM

Do you have the source for the "ingestion" process? Wouldn't it be easier
to modify that to provide the metrics? ;}



Cheers,
Tink

katkota 06-23-2009 03:16 PM

I wish i did, that's why i'm trying to write a script to do that using the tool but i need help with it

Tinkster 06-23-2009 03:24 PM

Code:

#!/bin/bash
start=$(date +"%s")
while ! grep "STAT ONLN" $1 2>&1>/dev/null
do
  sleep 1
done
finish=$(date +"%s")
echo  $(( finish - start )) "seconds"

where you pass the file-name you want to check to the script on
the command line.



Cheers,
Tink

katkota 06-23-2009 03:31 PM

But i have to run the tool in order to get the results that can have "STAT ONLN", in other word, if my file called katkota.txt then in order to get the results, i have to run this command:

/opt/dev/chktool -getstat /home/katkota.txt

then i would see the output with the "STAT ONLN"

so only passing the file name to your code will be looking at the file without running the tool

Tinkster 06-23-2009 03:36 PM

Easy enough fix...

Code:

#!/bin/bash
start=$(date +"%s")
while /opt/dev/chktool -getstat $1|grep -v "STAT ONLN" 2>&1>/dev/null
do
  sleep 1
done
finish=$(date +"%s")
echo  $(( finish - start )) "seconds"


katkota 06-23-2009 04:08 PM

I did that but the script hangs without doing any thing. It seems like it's not running loop until the STAT becomes ONLN. As i explained the STAT at the beginning showing as CHEK then after few seconds it turns into ONLN and i think we should be running the tool using a loop until the STAT changes then calculate the time it took

Tinkster 06-23-2009 04:59 PM

Ooops ... my bad, take the -v out

katkota 06-24-2009 09:15 AM

Thanks a lot Tinkster for your help

katkota 06-24-2009 09:56 AM

Just a dummy question: what does "!" mean in "while ! grep "STAT ONLN" $1 2>&1>/dev/null"?

Tinkster 06-24-2009 02:52 PM

While NOT

katkota 06-25-2009 09:06 PM

Help to script find and grep then remove
 
Folks;
I'm trying to write a script to scan through a directory tree then for each file it finds, it run a command line tool, then if the results include the word "DONE", it removes the file.
In more details;
i have a Linux directory tree such as "/opt/grid/1022/store"
I'm trying to write a script going through this tree and every file it finds, it should run this command on it:

/opt/dev/chktool -getstat file_name |grep -v "DONE"

If the output include the word "DONE" then we need to remove it, if not, skip to the next one.

Any help is greatly appreciated

Tinkster 06-25-2009 10:59 PM

Looked so similar, I merged the two threads ;}

katkota 06-26-2009 02:39 PM

I know it looks similar but it's actually not. I think i didn't explain my self correctly:

I think i didn't explain it better,
What i'm looking for is to go through the directory tree, find any file under any subdirectory then run the tool on it, if the output include the word "DONE" then remove the file, if not, leave the file alone and go to the next file and do the same thing.

I hope that makes it more clear

Tinkster 06-27-2009 05:06 PM

Something like this might work ...

Create a file kill_done in your PATH.
Code:

#!/bin/bash
if `/opt/dev/chktool -getstat $1 |grep "DONE" 2>&1>/dev/null`; then 
  echo "killing $1 dead!"
  rm $1
fi

And run that under find's control....
Code:

find /path/to/subdirs -type f -exec kill_done {} \;

Again - untested.


Cheers,
Tink


All times are GMT -5. The time now is 10:06 PM.