?
Solved

curl as a variable breaks the script

Posted on 2014-07-19
2
Medium Priority
?
479 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 2000 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

CHALLENGE LAB: Troubleshooting Connectivity Issues

Goal: Fix the connectivity issue in the lab's AWS environment so that you can SSH into the provided EC2 instance.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses
Course of the Month12 days, 13 hours left to enroll

777 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