I need to run a bash script in a .lua file:

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


route add reject

The permissions for file.sh is [-rwxr-x---] root www-data

I'm getting the error "Arg list too long", if i put the bash code directly in the lua i get the same error:

os.execute ("route add reject")

So it think that it's because the entire bash code is being executed inside quote marks, reference: https://stackoverflow.com/q/11475221/10286151

This is the consts from my limits.h:


#define NR_OPEN         1024

#define NGROUPS_MAX    65536    /* supplemental group IDs are available */
#define ARG_MAX       131072    /* # bytes of args + environ for exec() */
#define LINK_MAX         127    /* # links a file may have */
#define MAX_CANON        255    /* size of the canonical input queue */
#define MAX_INPUT        255    /* size of the type-ahead buffer */
#define NAME_MAX         255    /* # chars in a file name */
#define PATH_MAX        4096    /* # chars in a path name including nul */
#define PIPE_BUF        4096    /* # bytes in atomic write to a pipe */
#define XATTR_NAME_MAX   255    /* # chars in an extended attribute name */
#define XATTR_SIZE_MAX 65536    /* size of an extended attribute value (64k) */
#define XATTR_LIST_MAX 65536    /* size of extended attribute namelist (64k) */

#define RTSIG_MAX     32


How can i fix it? I tried to change the ARG_MAX to:

ARG_MAX       29107299

But it did not changed anything. I use Ubuntu 16.

When i searched about this i realized that this problem is because of the ARG_MAX, and what defines ARG_MAX is the file /usr/include/linux/limits.h, but i'm not sure because in the file limits.h my ARG_MAX is 131072, but when i do getconf ARG_MAX i get 2621440

  • What is route on your system? (what does type route say). As to modifying limits.h, you shouldn't do that, ever -- it will either have no effect whatsoever or badly break the C programs you compile them from source. – mosvy May 8 '19 at 16:20
  • I did type route and it shows route is /sbin/route. You said that i should not modify the limits.h and it could breal C programs, it does not make permant damage, right? I undoed the modifications, rebooted, and the system is working fine. Althought i still have the problem with the "Arg list too long". – mario May 8 '19 at 16:32
  • Are you certain it's actually this command that generates the error? – Kusalananda May 8 '19 at 17:07
  • @Kusalananda about the code yes i'm sure, because i only execute this command pastebin.com/raw/U4p9SvDG I tried to execute simple commands like echo 'abc' and it worked, so i think that the problem is really the "Arg list too long" – mario May 8 '19 at 17:29

The list of errors you've referenced in your PasteBin is misleading you.

The error you're receiving is number 7, but this is a program exit code and almost certainly not a system error code. They are completely unrelated.

I believe that the actual problem is simply that you are trying to add the same rejection route twice:

# route add reject; echo SS=$?
# route add reject; echo SS=$?
SIOCADDRT: File exists

You would also get the same exit code from route if you tried to delete a non-existent route:

# route delete reject; echo SS=$?
# route delete reject; echo SS=$?
SIOCDELRT: No such process

To fix the problem you need to manage your wrapper. You can either test for a rejection route before trying to add it, or simply discard the error return. This example favours the second (simplistic) approach, but you may need to take the other option:

route add reject 2>/dev/null
exit 0

(You do know how to pass and reference parameters to a script using "$1" and friends, rather than embedding IP addresses verbatim, don't you?)

| improve this answer | |
  • After i run route add reject; echo SS=$? with a user that has no root privileges i got this output: SIOCDELRT: Permission denied SS=7, so i realied that the problem was because the file.sh was not being executed with sudo, and i thought i was executing file.sh as root (which was not). – mario May 8 '19 at 22:21
  • After searching a while i found this answear that solved this problem askubuntu.com/a/153406/928635 and this is how my sudoers is now: pastebin.com/raw/PU77L1CT and i gave 500 [-r-x------] permision to the folder and file.sh. Do you think it's safe? I saw some people saying that this method is not that good, but i don't know about my case. – mario May 8 '19 at 22:22
  • The list of errors i was following was indded not giving me the correct information, and of couse my code was not being debugged correctly, It was only logging the exit code. – mario May 8 '19 at 22:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.