So I am trying to do something like:
%DECLARE Variable `cat src/documents/item.json`;
Filter BY field = Variable;
But I am getting an error saying:
ERROR org.apache.pig.Main - java.lang.RuntimeException: Error executing shell command: Command exit with exit code of 1
Can someone suggests what's wrong? Thanks!
Most likely "src/documents/item.json" doesn't exist and failing.
Interesting that I fixed
https://issues.apache.org/jira/browse/PIG-5349
just today that would have shown proper error message in addition to the exit code.
With that change, it should print out something like
"cat: src/documents/item.jsonl: No such file or directory"
Related
Any help is appreciated:
I am running a simple java currency converter application and trying to test it using conditional bash statements. For this test I am seeking to test when the user doesn't enter any value into the application what the resulting output is. Here is the bash script:
#!/bin/bash
input=""
expectedOuput="Please enter correct input"
actualOutput=$(java CurrencyConverter $input)
if [ $expectedOutput == $actualOutput ]; then
echo "Test 1 Passed"
else
echo "Test 1 Failed"
fi
I am aiming for the test to fail and echo this, however the script just returns the java error instead of echoing, like this:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
at CurrencyConverter.main(CurrencyConverter.java:12)
I am newer to bash scripting so have been changing the syntax, I just cant seem to stop the java error being printed
The exception message is printed to stderr, so if you want to get it in actualOutput (perhaps misleading name now):
actualOutput=$(java CurrencyConverter "$input" 2>&1)
you can also check the exit status of the java command.
Also check misspelled expectedOuput and use of quotes.
Use https://www.shellcheck.net/.
And the ArrayIndexOutOfBoundsException it's definitely something you should fix in your java code.
I have the following bash code in a script file:
if [ 'false' == 'true' ]
then
write_map() >> 'groups.txt'
Groups='groups.txt'
fi
When I try to run the script, I get this message from bash, and nothing is run:
syntax error near unexpected token `>>'
Why is >> an "unexpected token?
Why is bash failing on code that is inside an "if" that won't be run?
This bash code was created by Cromwell wdl. write_map is a wdl function, not a bash function. Could that be what's breaking bash?
So, there were two issues
write_map was being called wrong in the wdl code that was the source for this bash code
When called correctly, write_map is turned into a file, and you can't >> a file (you have to cat it then >>)
I am executing a kubectl command in a bash script and storing the output in a variable. When the kubectl command executes successfully I am getting the correct output in the variable, but when it does not execute successfully the variable is empty and the error message is not available in the variable. I want the error values to be stores in the variable.
Example:
GET_PODS_COMMAND="$(kubectl get pods -n mlsh-$JOBNAMESPACE --selector app=$POD_SELECTOR --template '{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}')" #kubectl command. Please assume mlsh-$JOBNAMESPACE and $POD_SELECTOR have correct values
GET_PODS_COMMAND_OUT=$GET_PODS_COMMAND
echo $GET_PODS_COMMAND_OUT #Printing command result
When the command execution is successful I get the pod name in GET_PODS_COMMAND_OUT but when the command output is "No Resources Found" value for GET_PODS_COMMAND_OUT is blank.
I read that I have to redirect the stderr to stdout as stated in below articles:
Bash how do you capture stderr to a variable?
https://www.reddit.com/r/kubernetes/comments/98s8v6/why_cant_i_store_outputs_of_kubectl_commands_in_a/
Still struggling to understand how exactly to achieve this.
Here is what I have tried:
GET_PODS_COMMAND_OUT="$(GET_PODS_COMMAND 2>&1)" #gives the error: GET_PODS_COMMAND: command not found
New to linux so any help is appreciated. Thank you.
I have a CI CD pipeline where I use a bash task to execute some script.
I want the build to fail if the script fails. So now I implemented an exit code where the bash script needs to fail. All good except for the error message.
I want to use a exit code whereby I can set an error message something like:
exit "script failed because alerts were found"
But I found online that you can only pass integers to your exit code.
Tried to fix it with:
echo "fail message"
exit code 2
But on my pipeline I got the Bash exited with code '2'. message and after i open the task output i can see my echo message.
Don't know if this is a Azure DevOps issue or I can fix this in bash. Anyone has any ideas?
[EDIT] Tried it with trap inside my local machine, and the custom error message works. But the same thing didn't work in Azure DevOps. I might think this is not possible in Azure DevOps -_-. Is there someone who already tried this ?
Perhaps the console in the screenshot shows only the script's standard error?
I would try something like:
echo "fail message" 1>&2
exit code 2
I'd suggest you have a look at "trap" command :
https://www.shellscript.sh/trap.html
and try something like :
trap 'your_function' EXIT
I'm building a script that uses a while loop like the following:
$sync=0
while [ $sync -eq 0 ];
do
body of the loop where $sync get changed sevaral times
done
The probleme is when I execute the script it gives me an error saying:
enter code hereline 53: 0=0: command not found
Please help me, thanks in advance
Change $sync=0 to sync=0. bash is not perl, so don't use the $ when assigning to a variable.
See http://www.gnu.org/software/bash/manual/bashref.html#Shell-Parameters
PS, the error message is useful: what is on line 53 in your script?