Link to home
Start Free TrialLog in
Avatar of SysExpert
SysExpertFlag for Israel

asked on

Perl issue with @ in backticks for curl

I have a perl script that calls a curl command via backticks.
Because of the locked down environment I work in, I can not add any modules to the basic perl install ( 5.05 on most or 5.8.8 on the newest machines).
I have a problem with the @ in a curl command that allows input from a file: curl -d@filename

perl compalins that   :
Can't use string ("home/xymon/server/ext/check_webl") as an ARRAY ref while "strict refs" in use at ./xy_weblogic_chk.pl line 155.
 `$CURL --connect-timeout 5 -m 15 -d@$XML_FILE  http://$opt_IP/middleware 2>&1 | grep "/result"  > $infile` ;
 this cmmand works fine in a shell script
 
 How do I escape or fix the command to get it to work in backticks  or other solution.

 
 Thanks in advance.
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

Did you try to escape the @ with \ ?

`$CURL --connect-timeout 5 -m 15 -d\@$XML_FILE  http://$opt_IP/middleware 2>&1 | grep "/result"  > $infile` ;
Avatar of SysExpert

ASKER

That messes up the curl command

curl: (7) Failed to connect to 0.0.0.1: Invalid argument
Strange. \ is a valid escape char in perl.

You could try single quotes, but that's just a guess:

`$CURL --connect-timeout 5 -m 15 -d '@'$XML_FILE  http://$opt_IP/middleware 2>&1 | grep "/result"  > $infile` ;
What would the curl command be if you gave it directly instead of from perl?

Also, what is in $opt_IP?
Better use perl module instead of external program.
http://curl.haxx.se/libcurl/perl/easy.pm.html
ASKER CERTIFIED SOLUTION
Avatar of stefan73
stefan73
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial