Solved

curl as a variable breaks the script

Posted on 2014-07-19
2
444 Views
Last Modified: 2014-07-19
The following variable was being used in a bash script;

CURL="curl -o /dev/null -u "$USERNAME:$PASSWD" --connect-timeout 5 -X POST"

Then, in my script, I would use the following;

$CURL -F function=clean_reports $SERVER_URL/myapp.php

I found that curl wasn't sending anything to php until I removed the variable and turned each curl line into the following;

 curl -o /dev/null  -u "$USERNAME:$PASSWD" --connect-timeout 5 -X POST -F function=clean_reports $SERVER_URL/myapp.php

Why? And how can I use this variable to shorten my lines?
0
Comment
Question by:projects
2 Comments
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
ID: 40206754
Hi,

I assume that the variables USERNAME and PASSWD are not yet filled when the CURL variable is set.

This will lead to a command "$CURL" looking like this:

curl -o /dev/null -u :  --connect-timeout 5 -X POST

which is certainly not correct. The content of CURL will stay the same even if the variables are filled later in the script before running "$CURL ... ..."

So either fill both variables USERNAME and PASSWD before setting CURL, or, if this is not possible,
you should try this:

CURL='curl -o /dev/null -u "$USERNAME:$PASSWD" --connect-timeout 5 -X POST'

Please note the single quotes!

Later in the script, once the required variables are filled run:

eval $CURL ... ...
0
 

Author Comment

by:projects
ID: 40206759
Should have caught that myself. Yes, the username and password were AFTER the variable.

Thanks for the help, all fixed now.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

I am a long time windows user and for me it is normal to have spaces in directory and file names. Changing to Linux I found myself frustrated when I moved my windows data over to my new Linux computer. The problem occurs when at the command line.…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now