-2

I'm trying to create a script which checks updates for apache and some other web server stuff for custom web panel and I'm having hard time while grep'ing current installed version of apache.

I tried to use that command to grep version of apache but the output is not containing numbers.

My command:

/usr/local/apache/bin/httpd  -v | grep  "version" | cut -d " " -f 3

And I'm getting this output:

Apache/2.4.46

And I need just 2.4.46 part of this thing.

BTW. There is the output of full /usr/local/apache/bin/httpd -v command:

Server version: Apache/2.4.46 (Unix)
Server built:   Aug 20 2020 22:34:56

I'm not familiar with linux that's not my active job. I hope someone will figure it out for me. Thanks.

emirefek
  • 452
  • 4
  • 9

1 Answers1

0

Use grep -o '[0-9]\+\.[0-9]\+\.[0-9]\+':

$ /usr/local/apache/bin/httpd -v grep -o '[0-9]\+\.[0-9]\+\.[0-9]\+'
2.4.46

to match digits, full stop, digits, full stop, digits

Paolo
  • 21,270
  • 6
  • 38
  • 69
  • Oh, I wasn't know. BTW. I'm using that ugly code for grabing latest version. Do you have any idea about that too? **curl -Ss "https://downloads.apache.org//httpd/" | grep CURRENT-IS- | cut -b 64-69** – emirefek Aug 21 '20 at 16:14
  • You should ask a different question for that. This question was answered. I'll be happy to help you in a different question. – Paolo Aug 21 '20 at 16:15
  • Okay. I'm new on stackoverflow. I'm learning. Thanks a lot!!! – emirefek Aug 21 '20 at 16:19