Lua won't execute bash script - linux

I'm using Lua script with ngnix to generate ISO file.
Lua script is parsing request and it should pass it to genisoimage command.
I've tried with:
local pack_cmd = "genisoimage -V" .. some_other_name
os.execute(pack_cmd)
Command is not successfully executed and as return code I get 3328. I've
tried with absoulte path (/usr/bin/genisoimage and /bin/genisoimage) but
it's not working.
I've tried simple workaround - Execute genisoimage command inside bash script
and in Lua script run it like this:
local pack_cmd = "bash /absoulte/path/script.sh " .. some_other_name
os.execute(pack_cmd)
Still not working and getting same exit code. Also tried to catch what's wrong but it look likes command genisoimage is never executed.
local pack_cmd = "bash /absoulte/path/script.sh " .. some_other_name .." >> error.log"
os.execute(pack_cmd)
Version with handles is not working as well
local handle = io.popen(pack_cmd)
local result = handle:read("*a")
handle:close()
If I execute pack_cmd string manually everything works OK. Executing bash script is also working.

The problem was with permissions for www-data user.

Related

Bash - current_history doesnt execute

im trying to call the following within a bash script:
`history -a current_history`
it is supposed to create the file with the commands executed this session.
Works perfectly fine in a shell enviroment
Does not work within a bash script
What am i doing wrong?

How to solve bash error "syntax error at line 3: 'CYBER_UNAME=$' unexpected"?

This error happens when I run a software containing bash script with beggining like this:
#! /bin/sh
CYBER_UNAME=$(uname)
CYBER_UNAME_M=$(uname -m)
I tried to execute these two commands in terminal and it works fine. This error only happens when I run the shell script. What should I do?
The result of 'uname' is SunOS. This shell script cannot be modified since it's protected on our server.
The line
#! /bin/sh
should read:
#!/bin/bash
So, that script will probably never really work.
If you cannot modify the script in situ, you might want to copy it to your local directory and correct it.
Otherwise,
tail +2 scriptname|/bin/bash
might work.

How to run shell script without typing bash (bash command error:mapfile not found)

I am using mapfile -t to obtain content of a text file and assign it to array.
In Jenkins it works fine where it will prompt steps and what command executed in console output .When I try to run in local console for example putty it prompts.
mapfile: not found [No such file or directory]
I know that mapfile is a bash command is and I am able to run the shell program after typing bash and executing the script.Is there anyway that I don't need to type bash in order to run the program ?I include #!/bin/bash -x on top of the script it still display the same error .The reason I don't want to type bash and execute the script is due to that it did not show what are the errors when the script dies.It did not display the error handling process that was in the script and it did not display output when it runs the command.
Please open a new file called script in a text editor. Type your program in:
#!/bin/bash -x
set -e
item=$1
if [ $item = '-database' ] then
mapfile -t DATA < $DATA_FILES
fi
save the file, execute chmod u+x and then
./script "-database"
to run it.
That's it.
However, that script will print nothing.

how to execute shell script from soapui groovy script?

I have shell script which is kept on remote server(linux machine) and I am trying to call that shell script in between the execution of various test cases of SOAPui from windows.
So I have prepared a groovy script:
def command="/usr/bin/ssh -p password username#IP_address bash -s < /home/test.sh"
def proc=command.execute().text
proc.waitFor()
But unfortunately, I am receiving an error:
java.io.IOException: Cannot run program "/usr/bin/ssh": CreateProcess error=2, The system cannot find the file specified error at line: 6
I tried to search more on this, but couldn't get the resolution. Some of the links were:
How to execute shell script using soapUI
http://groovy-lang.org/groovy-dev-kit.html#process-management
If as you comment you've a putty.exe installed on Windows you can try with the follow.
First of all create a file in your Windows local with the commands to execute remotely for example I create the follow C:/temp/commandsToRunRemotely.txt then in this file put the command you want to execute. As a sample I use the follow command:
echo "test remote execution" > /tmp/myfile.txt
Then from groovy script in SOAPUI call putty.exe passing the local file which contains the commands to execute remotely:
def command = "C:/path/to/putty.exe -ssh user#IP -pw pass-m C:/temp/commandsToRunRemotely.text"
def proc = command.execute()
proc.waitFor()
Note that if you've putty.exe in your Windows path, you can simply use putty.exe instead of full path.
This is only an ilustation sample, but if you want to execute a shell script remotely instead of echo "test remote execution" > /tmp/myfile.txt in the commands file use directly the path for your script: /home/test.sh
I get the Putty command line options from this nice answer
Hope it helps,

exec command in bash doesn't work when calling a shell script

The following are two shell scripts stored in the same folder with execute permissions on both:
shell1.sh
#!/bin/bash
exec shell2.sh
shell2.sh
#!/bin/bash
pwd
When trying to execute shell1.sh I am getting the following error:
./shell1.sh: line 3: exec: shell2.sh: not found
Is there something I am doing incorrectly? This works in other machines though but just in one particular server its not working.
Any suggestions would be helpful.
The current dir is not part of your PATH.
Try
exec ./shell2.sh

Resources