Solved

curl as a variable breaks the script

Posted on 2014-07-19
2
463 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 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Utilizing an array to gracefully append to a list of EmailAddresses
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
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…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

733 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