0

I'm writing a bash script to make a request on a server to send information via API and change the status about that information.

From terminal this works for me:

curl -s -w "GET" https://mysite/page.php?id=43982934&send=Yhd6yryr87237846dh&status=1";

If I go from browser on the same URL, it works. But when I run this from inside my script with this command, nothing works.

cmd='curl -s -w "GET" https://mysite/page.php?id=43982934&send=Yhd6yryr87237846dh&status=1"';

Tried to run it directly like terminal, but couldn't get it to work.

EDIT

Script is something like this:

#!/bin/bash
cmd='curl -s -w "GET" "https://mysite/page.php?id=43982934&send=Yhd6yryr87237846dh&status=1"'
    if [ "$var" != "$extension" ]; then
            ffmpeg -i /var/www/html/temp/name.extension -c copy /var/www/html/temp/namefile.extension
    fi;
cmd='curl -s -w "GET" "https://mysite/page.php?id=43982934&send=Yhd6yryr87237846dh&status=2"'

I need to set a status for each ffmpeg process!

Community
  • 1
  • 1
tidpe
  • 325
  • 3
  • 15
  • 1
    can you show your script ? – Thanh Nguyen Van May 14 '18 at 09:42
  • 1
    Nothing works? What is the output from CURL? – Nick.Mc May 14 '18 at 09:43
  • This is another classic case of [I'm trying to put a command in a variable, but the complex cases always fail!](http://mywiki.wooledge.org/BashFAQ/050) Don't ever use variables to store commands, they are meant for holding data. Use a function or an array. The issue you are facing is the result of Word splitting of the individual arguments when you define it in a variable `cmd`, the `actual` curl command did not get to see the entire list of arguments. – Inian May 14 '18 at 11:41
  • 1
    Use an array, `cmdArgs=() cmdArgs=( "curl" "-s" "-w" "GET" "https://mysite/page.php?id=43982934&send=Yhd6yryr87237846dh&status=1" )` and do a proper quoted array expansion as below which will preserve your individual words and run the command without any splitting done. `"${cmdArgs[@]}"` or use a function `curlCmd() { curl -s -w "GET" "https://mysite/page.php?id=43982934&send=Yhd6yryr87237846dh&status=1" }` and call it as `curlCmd` – Inian May 14 '18 at 11:41
  • thank! solved with `cmdArgs=( "curl" "-s" "-w" "GET" "https://mysite/page.php?id=43982934&send=Yhd6yryr87237846dh&status=1` – tidpe May 14 '18 at 14:10

0 Answers0