0

I need to do some testing using curl against our web farm. Each server has some default page with some verbiage on it like this:

"Welcome to webappsrv01"
"Welcome to webappsrv02"   and so forth.

How can I use curl and grep(?) to grab the "Welcome to webappsrv(?)" string so I can see it the output on the screen as I hit the webfarm? I need to know what server I am hitting.

1

Use:

curl -s https://example.com | grep -o "This doma.."

Output:

This domain

Options:

  • -s in curl is silent mode - it will not print progress

  • -o in grep is only matching - only matching string will be printed

  • This doma is pattern and two dots .. means any character can be there so in your case it will be two digit numbers

-1

Not quite sure what you are asking, but as far as i can see you can use something like this

$ curl <url> | grep -Po 'Welcome to webappsrv\d+'

-P - PCRE regex, we use this for our \d which matches digit

-o - only matching word, not whole line

+ in regex - match 1 or more times digit

  • Why did i get downote? – Tryna Learn Somethin Feb 21 at 18:33
  • Tryna - This is good. I am indeed trying to catch the following two letters/digits after the host name (webappsrv01/02) etc. I made a mistake though. Some of the older servers in our lab have text like this: "webapp 1" or "webapp 2". IS it possible to skip a space and the grab then grab the number? Can you show me that please? I did Upvote but I don't have enough reptuation credits for it show up. – jogle900 Feb 21 at 18:57
  • Tryna - The second example didn't work for me. I got the following error: -bash: syntax error near unexpected token `(' These examples are still very useful and appreciated. – jogle900 Feb 21 at 19:10
  • Matej - Your example worked great as well and it simpler for this specific task. I did UPvote as well. Thank you, – jogle900 Feb 21 at 19:10
  • @jogle900 $ curl https://example.com | grep -Po '(Welcome to websrvapp01\d+)|(webapp\s\d+)' will match "Welcome to websrvapp01" aswell as "webapp 1" and also "webapp 02" – Tryna Learn Somethin Feb 21 at 20:06

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.