0

I'm trying to get some data (mac adresses more precisely) from a server thank to its API. The data is in json format and I can't have the output that i'm expecting. And by the way I want to redirect the output that i expect (So the json data) towards a file.

For example: i'm doing this :

curl -i -H "Accept: application/json" -X GET https://internal.mycompany.com/api/install/get_macs.php?token=xxxxxxxxxxxxxxx" > mac.txt

And the output i get is this:

[1] 1308
mo@servertest:~$
HTTP/1.1 200 OK
Date: Wed, 21 Apr 2021 15:13:19 GMT
Server: Apache/2.4.38 (Debian)
Content-Length: 62
Content-Type: text/html; charset=UTF-8

[{"mactabwifi":"","mactabwired":"","maccam":"","macnuc":null}]

And I have to press enter a second time otherwise it is not doing anything. Once I press enter I get this:

[1]+  Done                    curl -i -H "Accept: application/json" -X GET https://internal.mycompany.com/api/install/get_macs.php?token=xxxxxxxxxxxx

Do you have any idea how i can get only the data I need without pressing enter a second time?

And by the way, after all of this, when I'm doing a cat of my file mac.txt, nothing there is nothing..

Thank you for the help!

1

1 Answer 1

1

You should be able to have your desired output by using this command:

curl -H "Accept: application/json" https://internal.mycompany.com/api/install/get_macs.php?token=xxxxxxxxxxxxxxx > mac.txt

Curl defaults to GET HTTP method, and -i option is used to include header in response, otherwise you'll have only body as output.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.