Reputation: 49
I am looking to cut the task number which is highlighted in the output. However, normal grep or sed commands or redirection to text file for getting the desired output is not working. As the curl is writing on the terminal screen, these operations arent working. Please suggest.
vcap@jumpbox-sagdf-staging:~ $ curl -v -s -k 'https://admin:[email protected]:25555/deployments/concourse/vms?format=full' * Hostname was NOT found in DNS cache
Trying 10.19.1.1....
Connected to 10.19.1.1 (10.19.1.1) port 25555 (#0)
successfully set certificate verify locations:
CAfile: none
CApath: /etc/ssl/certs
SSLv3, TLS handshake, Client hello (1):
SSLv3, TLS handshake, Server hello (2):
SSLv3, TLS handshake, CERT (11):
SSLv3, TLS handshake, Server key exchange (12):
SSLv3, TLS handshake, Server finished (14):
SSLv3, TLS handshake, Client key exchange (16):
SSLv3, TLS change cipher, Client hello (1):
SSLv3, TLS handshake, Finished (20):
SSLv3, TLS change cipher, Client hello (1):
SSLv3, TLS handshake, Finished (20):
SSL connection using ECDHE-RSA-AES128-GCM-SHA256
Server certificate:
subject: CN=director
start date: 2017-06-20 13:19:23 GMT
expire date: 2019-06-20 13:19:23 GMT
issuer: CN=rootCA
SSL certificate verify result: unable to get local issuer certificate (20), continuing anyway.
Server auth using Basic with user 'admin'
GET /deployments/concourse/vms?format=full HTTP/1.1
Authorization: Basic YWRtaW46OHdId1lEVlIwakJCZ3c=
User-Agent: curl/7.35.0
Host: 10.19.1.1:25555
Accept: /
>
< HTTP/1.1 302 Moved Temporarily
< Server: nginx
< Date: Fri, 30 Jun 2017 04:07:19 GMT
< Content-Type: text/html;charset=utf-8
< Content-Length: 0
< Connection: keep-alive
< WWW-Authenticate: Basic realm="BOSH Director"
< Location: https://10.19.1.1/tasks/1017317
< X-XSS-Protection: 1; mode=block
< X-Content-Type-Options: nosniff
< X-Frame-Options: SAMEORIGIN
<
Upvotes: 1
Views: 1677
Reputation: 58124
Since you want to extract the piece on the right of the right-most slash of the Location:
response header, I would use this:
curl -so /dev/null -w "%{redirect_url}\n" $URL | sed 's:.*/::g'
so that with your original URL use case it would look like (I added the -k back in this version):
curl -kso /dev/null -w "%{redirect_url}\n" 'https://admin:[email protected]:25555/deployments/concourse/vms?format=full' | sed 's:.*/::g'
(Do note that you've exposed your user name and password to the world here...)
Upvotes: 0