How to run bash scripts in Mule ESB

By | September 29, 2015

mule she bangIntro

I wanted to figure out how to run bash scripts in Mule ESB so my first point of call? Google. Google returned a few useful results. Primarily:

  • and

Being new to this I couldn’t make out much but 2 things stuck out. Groovy and “ls”.excute(). Armed with these 2 clues, I tried to give it a go.


The main motivation to execute a bash script was to control an LED light which I’ll explain in a future post.

What I did?

The first thing I did was to create a script.

echo "hello world" > file_created_by_mule_script.txt

I named this file “” and placed it in my mule-enterprise-standalone-3.7.1 folder. I tested this out manually first to check for errors of which there were none.

If the file is executed, via


then a file called file_created_by_mule_script.txt should be created and when opened, hello world should appear as the content.

The location took me a while to figure out. The Mule Flow zip file is placed in the /apps folder but the script will get executed in the apps parent folder.

Once I figured that out, the rest involved a bit of trial and error but was relatively simple. Hopefully this knowledge will mean do you can avoid the trial and error piece.

Next up was to create the Mule flow. The simplest flow included only 2 activities:


Here is the XML in case someone wants to try this out.

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="" xmlns:doc="" xmlns:http="" xmlns:scripting="" xmlns:spring="" xmlns:xsi="" version="EE-3.7.1" xsi:schemaLocation="">
 <http:listener-config name="HTTP_Listener_Configuration" host="" port="8081" doc:name="HTTP Listener Configuration" />
 <flow name="executebashscriptFlow">
 <http:listener config-ref="HTTP_Listener_Configuration" path="/createfile" doc:name="HTTP" allowedMethods="GET" />
 <scripting:transformer doc:name="Groovy">
 <scripting:script engine="Groovy"><![CDATA["".execute()]]></scripting:script>

The key here is the “”.execute(). This is the Groovy syntax required to execute a bash command.


I got stuck a few times with permissions. The files I created often did not have executable permissions so I got permission denied errors. Check your permissions with:

ls -l

and ensure you have the right permissions set.

One thought on “How to run bash scripts in Mule ESB

  1. ram

    to execute this script how did u log into in that unix box ?


Leave a Reply

Your email address will not be published. Required fields are marked *