1

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?

  • 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
6
./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.

  • Or use grep -m 1 and avoid the head -n 1 – Sirex Jan 4 '13 at 0:43
2

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.

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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