4

I've ran into a strange issue. I'm trying to script my router to collect usage stats and other stuff. I'm making one cURL to the auth URL to get a valid session id, then another using that session id to the page I need.

Here is my script:

SESSION_ID=$(curl --silent -D - -X POST http://10.0.0.1/login.cgi -d'admin_username=admin&admin_password=admin' | grep 'SESSION' | sed 's/Set-Cookie: SESSION=//' | sed 's/; path=\///')
echo $SESSION_ID # 1234567890
curl -v -H "Cookie: SESSION=$SESSION_ID" http://10.0.0.1/modemstatus_dslstatus.html

If I manually take SESSION_ID and insert it in place of '"$SESSION_ID"' everything is dandy. cURL shows the headers (via -v) and they are correct. Running the command while manually inserting the session id produces identical headers.

I'm sure it's something small. Please teach me something :)

7
  • Try curl -v -H "Cookie: SESSION=$SESSION_ID" ... Commented Dec 19, 2016 at 3:25
  • You seem to have nested single-quotes in ` ' Cookie: SESSION= ' " $SESSION_ID" ' ' ` (extra spaces added for clarity) that certainly dont do what you want. (Posted at same time as @heemayl. We're basically saying the same thing.) Commented Dec 19, 2016 at 3:26
  • @heemayl No go :( Commented Dec 19, 2016 at 3:27
  • @Mort Updated to reflect heemayl's suggestion, which eliminates those nested quotes. Commented Dec 19, 2016 at 3:28
  • Try set -x and then run the curl command. Also, what does printf '%q\n' "$SESSION_ID" report? Commented Dec 19, 2016 at 3:29

1 Answer 1

1

Check for carriage returns \r in your variables which wouldn't appear with a simple echo in some cases.

Sign up to request clarification or add additional context in comments.

Comments

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.