简体   繁体   中英

Invoke Curl from within shell script

I've below code in shell script

#!/bin/bash

oauth_consumer_key='sdfsfsd'
oauth_consumer_key_secret='1sdfsdfs1'
oauth_token='5wrwerwr476a1737fe09de2e4ew'
oauth_token_secret='ec2231779e4'

url='https url goes here'

token=$(./oauth $oauth_consumer_key $oauth_consumer_key_secret $oauth_token $oauth_token_secret GET $url)

curl_path='/usr/bin/curl'
curl_args="-H 'Authorization: $token'"

resp=$($curl_path $curl_args $url)

echo $resp

Here, I'm first running oauth.sh from this program by passing params & capturing output in token which works as expected. And this output looks as shown below:

OAuth oauth_consumer_key="45435", oauth_token="4r43", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1415328827", oauth_nonce="4535345", oauth_version="1.0", oauth_signature="bKeewO%2BTJ7IHjurhtaftn9dNfxA%3D"' 'my url goes here'

Now, I need to invoke curl command from this program by passing above as param as shown below:

curl -H 'Authorization: OAuth oauth_consumer_key="45435", oauth_token="4r43", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1415328827", oauth_nonce="4535345", oauth_version="1.0", oauth_signature="bKeewO%2BTJ7IHjurhtaftn9dNfxA%3D"' 'my url goes here'

When I run above curl command from terminal console, it works but from my shell script it gives error couldn't resolve OAuth

Can anyone help me out in fixing this issue?

Thanks!

It looks like this line is looking for "oauth" in the current directory.

token=$(./oauth

I would try putting the absolute path to oauth instead of ./oauth and see if that works.

If that doesn't work, I would strip it down a little and comment out everything after that line and just echo $token and see if it's showing the expected results and go from there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM