Solved

curl as a variable breaks the script

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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

The purpose of this article is to demonstrate how we can use conditional statements using Python.
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
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.:
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

696 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