Search code examples
javamulesoft

Mulesoft cannot run a shell script


I am trying to run a shell script in a flow in Mulesoft's Anypoint Studio.

While I can get some basic shell to run I cannot get my script to run. This is what my script looks like:

#!/bin/ksh
export JWHome=${pwd}
export LOG4J_JAR=$JWHome/lib/log4j-1.2.7.jar
export CLASSPATH=$JWHome/lib/java.jar:$LOG4J_JAR:$JWHome

I set the above script as a payload and execute it from a Groovy script by running:

payload.execute().text

When I run this script I get the following error:

java.io.IOException: Cannot run program "#!/bin/ksh": error=2, No such file or directory
I get the same error when I remove "#!/bin/ksh" - For example when I run Export to set a variable.

How can I get this to run?


Solution

  • I'm assuming that what you did -you didn't provide enough details- is to use a Groovy script to execute the content of a string in the payload using the execute() method. That is failing because a shell script is not a single command. Only a shell can interpret it, but not as command line.

    You can try writing the shell script content to a file (example: myscript.sh, or use a temporary name), then execute the shell script by name ("myscript.sh".execute()). You will probably need to add the path to the file is correct otherwise the execute() method may not find it.