LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-23-2009, 03:24 PM   #1
katkota
Member
 
Registered: Jan 2008
Posts: 33

Rep: Reputation: 15
Talking 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
 
Old 06-23-2009, 04:13 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

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



Cheers,
Tink
 
Old 06-23-2009, 04:16 PM   #3
katkota
Member
 
Registered: Jan 2008
Posts: 33

Original Poster
Rep: Reputation: 15
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
 
Old 06-23-2009, 04:24 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
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
 
Old 06-23-2009, 04:31 PM   #5
katkota
Member
 
Registered: Jan 2008
Posts: 33

Original Poster
Rep: Reputation: 15
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
 
Old 06-23-2009, 04:36 PM   #6
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
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"
 
Old 06-23-2009, 05:08 PM   #7
katkota
Member
 
Registered: Jan 2008
Posts: 33

Original Poster
Rep: Reputation: 15
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
 
Old 06-23-2009, 05:59 PM   #8
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Ooops ... my bad, take the -v out
 
Old 06-24-2009, 10:15 AM   #9
katkota
Member
 
Registered: Jan 2008
Posts: 33

Original Poster
Rep: Reputation: 15
Thanks a lot Tinkster for your help
 
Old 06-24-2009, 10:56 AM   #10
katkota
Member
 
Registered: Jan 2008
Posts: 33

Original Poster
Rep: Reputation: 15
Just a dummy question: what does "!" mean in "while ! grep "STAT ONLN" $1 2>&1>/dev/null"?
 
Old 06-24-2009, 03:52 PM   #11
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
While NOT
 
Old 06-25-2009, 10:06 PM   #12
katkota
Member
 
Registered: Jan 2008
Posts: 33

Original Poster
Rep: Reputation: 15
Talking 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
 
Old 06-25-2009, 11:59 PM   #13
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Looked so similar, I merged the two threads ;}
 
Old 06-26-2009, 03:39 PM   #14
katkota
Member
 
Registered: Jan 2008
Posts: 33

Original Poster
Rep: Reputation: 15
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

Last edited by katkota; 06-26-2009 at 03:57 PM.
 
Old 06-27-2009, 06:06 PM   #15
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl script to capture system info? Zmyrgel Programming 4 04-18-2009 04:30 AM
Is it possible to capture the output of a interactive script? Akhran Linux - Newbie 4 04-11-2007 10:28 PM
Cannot locate cursor ID in X for capture script smudge|lala Programming 0 04-07-2006 09:26 PM
Searching for capture script. jabka Linux - General 1 10-07-2005 09:53 AM
Script to capture dynamic IP address scon Linux - General 4 02-21-2003 04:30 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:50 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration