2

The .lua file is being executed because i saw the strings from m.log() in my log but the bash code is not being executed. Why? There's something i'm missing? Also there's no errors in the logs about the command in os.execute().

#!/usr/bin/lua

function main()
m.log(1,"Starting script execution \n")
os.execute ("route add xx.xxx.xxx.xxx reject")
## i also tried os.execute ("/path/to/file.sh") and giving permision to execute with chmod +x filename.sh
m.log(1,"Script execution finished\n")
end

NOTE: I executed the command from os.execute() directly in my Command Prompt, and the IP was added to the route, so there's something wrong in my lua code...

I changed the permisions to 777 from the folder/file that have the .lua and .sh file only to test if it was a permision issue, and nothing changed, i also tried to change the owner and usergroup.

Edit - This one bellow was not working because it was on the /root/ folder, so i needed to moved it to /var/www/.

os.execute ("/path/to/file.sh")

But the bash code is not being executed, the os.execute is returning exit status 7 (Arg list too long), I searched about it and i realized that it's because the entire bash code is being executed inside quote marks: Why do I get "/bin/sh: Argument list too long" when passing quoted arguments?

How can i fix it?

mario
  • 337
  • 1
  • 3
  • 12

1 Answers1

1

You should check the result of os.execute, as it returns the exit status of the command as one of the results.

You can also use io.popen to run your script and check the generated output.

Paul Kulchenko
  • 22,780
  • 3
  • 28
  • 49
  • https://pastebin.com/raw/YB3QGurH This is the exit status, right? So what should i do with it? It did not show errors. And about the `io.open` i tried this https://stackoverflow.com/a/9676174/10286151, i also tried other methods that i found in forums, none worked. – mario May 07 '19 at 16:35
  • `When called without a command, os.execute returns a boolean that is true if a shell is available. ` I did checked it and it returned true. But i don't know what `shell is available` supposed to mean – mario May 07 '19 at 16:40
  • Looks like the exit status, but I would print all values returned from `os.execute`. What OS are you on? Assuming 1792 needs to be divided by 256, looks like the actual error returned is 7, which is "Arg list too long" (going by http://www-numi.fnal.gov/offline_software/srt_public_context/WebDocs/Errors/unix_system_errors.html), but this doesn't seem to be right in your case. – Paul Kulchenko May 07 '19 at 17:19
  • https://pastebin.com/raw/LnQk9wj3 i did the same but using the path to the `.sh` file instead, the exit code was 32256%256 = 126, and on your link the list error range is 1-124, my OS is ubuntu 16. I also tested this code https://stackoverflow.com/a/23833013/10286151 the exit code seems to be correct, exit code is 7 when i put the bash code directly in the function `io.open` – mario May 07 '19 at 18:26
  • "If a command is found but is not executable, the return status is 126." according to https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html – Paul Kulchenko May 07 '19 at 20:30
  • @nobody, did you find the reason? I don't have any further suggestions based on your updated answer, other than to experiment what commands are being executed to see what works and what doesn't. – Paul Kulchenko May 15 '19 at 00:29
  • Yes, i said it in the comment above. I was getting status 7 because the `route` needed to be executed as root. And I realized that many events can return status 7. – mario May 15 '19 at 00:45