Solved

curl as a variable breaks the script

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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Unable to disassociate and associate elastic IP address EC2-VPC 6 45
linux crontab output 3 66
AWS CLI issues with Tags 3 63
CentOS 7 Installation 7 58
Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

919 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

18 Experts available now in Live!

Get 1:1 Help Now