petere / plsh

PL/sh is a procedural language handler for PostgreSQL that allows you to write stored procedures in a shell of your choice.
Other
165 stars 21 forks source link

curl command execute within plsh #9

Open walpino opened 8 years ago

walpino commented 8 years ago

i want to execute curl from plsh

the procedure looks like

!/....

curl "$1"

and $1 looks like

'https://.....ewad.json' -v -X POST --data-urlencode 'address=fdfdf 38' --insecure --data-urlencode 'size=65' --data-urlencode 'hash=47b51e9dd1c6a833a7f3effe2ee9dc997632' --data-urlencode 'action=insert_ad' --data-urlencode 'region=14' --data-urlencode 'zipcode=3012' --data-urlencode 'app_id=homegate' --data-urlencode 'phone=07382' --data-urlencode 'email=unlead@hotmail.com' --data-urlencode 'body=Beautiful unfu' --data-urlencode 'phone_hidden=0' --data-urlencode 'price=1455' --data-urlencode 'category=1020' --data-urlencode 'rooms=4' --data-urlencode 'area=92' --data-urlencode 'company_ad=1' --data-urlencode 'lang=de' --data-urlencode 'name= ' --data-urlencode 'subject=2.5 room Apartment for rent' --data-urlencode 'no_licenseplate=1' --data-urlencode 'type=u' --data-urlencode 'store_id=49' --data-urlencode 'import=1' --data-urlencode 'external_ad_id=103466419'

the return value is curl(3) illegal character hmm but

if I execute this on the prompt everything works fine

do you have a hint whats wrong with this?

thanks

petere commented 8 years ago

Please show the exact function definition (CREATE FUNCTION ...).

walpino commented 8 years ago

just a simple example

CREATE OR REPLACE FUNCTION query (x int) RETURNS text LANGUAGE plsh AS $$

!/bin/sh

/usr/bin/curl www.zkb.ch > /tmp/a.html /usr/bin/wget www.zkb.ch > /tmp/a.html $$;

the curl throws an error the wget works

if I'm doing this on the prompt the curl works fine too

petere commented 8 years ago

And what is your output?

You probably have to run curl with -s and wget with -q or similar, because plsh will interpret any output to stderr as failure. Other than that, your example works for me.