Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm looking to get the version number of an app that doesn't have any kind of --version option.

I'm looking for a bash script that will start the process (it runs until killed), grep it's version number and then kill it.

Something like:

./server | grep version | kill $PID

Is that possible?

share|improve this question
    
Hmmm....what is the application for something like this? and kill what? The thing that runs indefinitely? –  mdpc Feb 8 '12 at 0:55
    
I clarified my question –  whatupdave Feb 8 '12 at 1:00
    
Is this a one time thing or are you going to have to do this many times? –  mdpc Feb 8 '12 at 17:09
    
many times, I'm pulling a file from a remote location and discovering which version it is –  whatupdave Feb 9 '12 at 19:23
add comment

3 Answers 3

up vote 5 down vote accepted
./server | grep version | head -n 1 && kill $PID

The head will stop the pipe after it has found 1 result.

If you want to capture the variable you should be able to do:

version=`./server | grep version | head -n 1` && kill $PID
echo $version

Edit: The suggestions for 'strings' is a better path if viable.

share|improve this answer
    
Or use grep -m 1 and avoid the head -n 1 –  Sirex Jan 4 '13 at 0:43
add comment

Do you actually need to run and kill it this way, or could you find the version by running strings over the binary?

Otherwise:

./server | grep user | kill `pgrep -P $$ server`

...should do the trick.

share|improve this answer
add comment

Does the version string follow any reasonable format? You might try running strings against the binary and see if you can build a pattern to match the version string.

Otherwise this gets a little hacky in bash. I'd probably do something like:

./server | grep version &>/tmp/out.$$ &
sleep 10  # <-- however long it takes for version to come out.
kill %1

Edit: Tarrant's answer is much better than mine.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.