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?

4
  • Try /sbin/route instead of route inside os.execute() Commented May 7, 2019 at 17:46
  • @EgorSkriptunoff Did not work, and the current problem i'm facing is about the exit status 7 (Arg list too long) Commented May 8, 2019 at 2:51
  • Try os.execute ("/bin/bash /path/to/file.sh") Commented May 8, 2019 at 7:23
  • The problem was because i needed to execute the .sh with sudo, and it did not has root privileges. Commented May 9, 2019 at 2:54

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

7 Comments

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 stackoverflow.com/a/9676174/10286151, i also tried other methods that i found in forums, none worked.
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
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 www-numi.fnal.gov/offline_software/srt_public_context/WebDocs/…), but this doesn't seem to be right in your case.
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 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
"If a command is found but is not executable, the return status is 126." according to gnu.org/software/bash/manual/html_node/Exit-Status.html
|

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.