How to insert variables from lua into bash correctly? It is necessary for the script to transfer 2 variables, here is the code:

location /script { content_by_lua ' lua_arg1 = ngx.var.arg_arg1 lua_arg2 = ngx.var.arg_arg2 command = "/usr/bin/script.sh "..lua_arg1 ..lua_arg2 local handle = io.popen(command); local result = handle:read("*a"); handle:close(); ngx.print(result);'; 

}

Here is the query: localhost: 1501 / script5? Arg1 = 1234 & arg2 = 4321

Here is the bash script:

 #!/bin/bash echo argument1 $1 echo argument2 $2 

And here is the result:

 argument1 12344321 argument2 

It turns out that the variables "stuck together", how to transfer them individually to the script so that it would be like this:

 argument1 1234 argument2 4321 
  • and if in lua_arg1 it will be '; rm -rf ~ / '? - strangeqargo pm
  • Thanks, I have already found a solution on another forum - Stas
  • one
    command = "/usr/bin/script.sh" ..lua_arg1 .. "" .. lua_arg2 - Stas
  • one
    so it will be correct - Stas

1 answer 1

Obviously, you need to insert a space between the arguments. after all, they are “stuck together” in the script itself.

 command = "/usr/bin/script.sh "..lua_arg1.." "..lua_arg2