curl command output in a variable

Ramesh

I am connecting to mySQL database using a shell script. After connecting to the mySQL database, I execute a query. The query gives me 300,000 URLs as the result.

For each of the 300,000 URLs I need to check if the URLs actually exist and need to update the table that the URL is checked for its existence.

I have planned on using the curl command. I am giving the command as below.

curl -s --head http://myurl/ | head -n 1 | grep "HTTP/1.[01] [23].."

If I just give the command in my shell, I am getting the response (like 301, 200 etc). However, I need it in a variable so that I can use it for some manipulation purposes. For example, like below.

$var = curl -s --head http://myurl/ | head -n 1 | grep "HTTP/1.[01] [23].."
echo $var;
if ($var == "some value")
{ 
    do something;
}
else
{
    do some other thing;
}
terdon

To capture the result of a command in a variable, you can use backticks (``) or, better, $(command). In your case, that would be:

var=$(curl -s --head http://myurl/ | head -n 1 | grep "HTTP/1.[01] [23]..")
echo "$var";
if [ "$var" == "some value" ]; then    
    do something;    
else
    do some other thing;
fi

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Curl command from Python Subprocess to store output into variable

From Dev

How do I pipe the output of a curl command to an environment variable and use it in another curl command?

From Dev

Reduce output of curl command

From Dev

bash variable in curl command

From Dev

bash variable in curl command

From Dev

Curl command to output filename with a timestamp

From Dev

Assigning the output of a command to a variable

From Dev

Set output of a command to a variable

From Dev

Set command output as variable

From Dev

redirecting output of command to variable

From Dev

Output piped command to variable

From Dev

Set output of a command to a variable

From Dev

Output a Command Stored in a Variable

From Dev

Save the output of a command to a variable

From Dev

How can I extract part of the output of a curl command and assign it to a shell variable?

From Dev

How can I extract part of the output of a curl command and assign it to a shell variable - part 2?

From Dev

Using a variable to execute a curl command

From Dev

CuRL command is not giving output as Url is not responding

From Dev

Use curl command output to send email

From Dev

my Curl command display special characters in the output

From Dev

Get output from curl command in python.

From Dev

store the output of powershell command in a variable

From Dev

Use the output of a shell command as a variable

From Dev

Capture command output in variable and suppress it

From Dev

Output of a command not passing to assigned variable

From Dev

Assign output of a shell command to a variable

From Dev

Get command coloured output in a variable

From Dev

Echoing output of command from variable

From Dev

execute TSQL command with an output variable

Related Related

  1. 1

    Curl command from Python Subprocess to store output into variable

  2. 2

    How do I pipe the output of a curl command to an environment variable and use it in another curl command?

  3. 3

    Reduce output of curl command

  4. 4

    bash variable in curl command

  5. 5

    bash variable in curl command

  6. 6

    Curl command to output filename with a timestamp

  7. 7

    Assigning the output of a command to a variable

  8. 8

    Set output of a command to a variable

  9. 9

    Set command output as variable

  10. 10

    redirecting output of command to variable

  11. 11

    Output piped command to variable

  12. 12

    Set output of a command to a variable

  13. 13

    Output a Command Stored in a Variable

  14. 14

    Save the output of a command to a variable

  15. 15

    How can I extract part of the output of a curl command and assign it to a shell variable?

  16. 16

    How can I extract part of the output of a curl command and assign it to a shell variable - part 2?

  17. 17

    Using a variable to execute a curl command

  18. 18

    CuRL command is not giving output as Url is not responding

  19. 19

    Use curl command output to send email

  20. 20

    my Curl command display special characters in the output

  21. 21

    Get output from curl command in python.

  22. 22

    store the output of powershell command in a variable

  23. 23

    Use the output of a shell command as a variable

  24. 24

    Capture command output in variable and suppress it

  25. 25

    Output of a command not passing to assigned variable

  26. 26

    Assign output of a shell command to a variable

  27. 27

    Get command coloured output in a variable

  28. 28

    Echoing output of command from variable

  29. 29

    execute TSQL command with an output variable

HotTag

Archive