1

I am trying to execute a command from lua script. The command is to simply run a python script named "sha_compare.py" of which receives 3 arguments where two of them are variables from the lua script - dady_data and sha:

local method = ngx.var.request_method
local headers = ngx.req.get_headers()

if method == "POST" then
   ngx.req.read_body()
   local body_data = ngx.req.get_body_data()
   local sha = headers['X-Hub-Signature-256']
   ngx.print(os.execute("python3 sha_compare.py"..sha..body_data))
else

The script fails because of the way I call the arguments. The actual command if I would have ran it from cmd would have been something like:

python3 python3 sha_compare.py sha256=ffs8df aaaaa

Please tell me how should I change my code to call the python script with 3 vars properly.

If it is not possible or hard to implement, please let me know how can I call a .sh script which will receive those 3 params.

1
  • What's inside body_data? Does it contain characters which are "magical" for shell? Commented Feb 28, 2021 at 18:34

1 Answer 1

1

You're not providing spaces between the arguments: you're trying to execute

python3 sha_compare.pysha256=ffs8dfaaaaa

Do this:

os.execute("python3 sha_compare.py "..sha.." "..body_data)

It's often easier to build the command up as a table, and the concat it for execution:

local cmd = { 'python3', 'sha_compare.py', sha, body_data }
os.execute(table.concat(cmd, " "))
Sign up to request clarification or add additional context in comments.

4 Comments

os.execute("python3 sha_compare.py "..sha.." "..body_data) doesn't work, won't even compile. I get error server 500. And the table option returns 512...
I added a full path to the script name. Now getting error 256.
Does body_data contains spaces and/or quotes? If so you'll have to make sure the value is properly quoted for the shell.
Can you please take a look over this thread as well? This is critical for me. Thanks. stackoverflow.com/questions/66527896/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.