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?

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

3 Answers

up vote 4 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.

link|improve this answer
feedback

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.

link|improve this answer
feedback

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.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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