Showing posts with label Apache Camel Exec. Show all posts
Showing posts with label Apache Camel Exec. Show all posts

Thursday, January 29, 2015

Apache Camel Exec - Run Executables

Assume you want to run an executable, you can utilize Camel's Exec component.
Such as:
exec://sh?args=-c+%22./someexec%22
It's pretty easy.

Sometimes you may get error message like "cannot execute binary file". Run the "file" command to check the executable's detail information.

If you get something like the following:
someexec: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, not stripped
It means that your executable is 64 bits but you're running it on a 32-bit OS.



Create a Successful Online Store at Bigcommerce! Try it Free Now!

Camel Exec IP Aliasing | Apache Camel Exec - Execute IP Aliasing Commands


IP Aliasing


IP aliasing is associating more than one IP address to a network interface. With this, one node on a network can have multiple connections to a network, each serving a different purpose. [1]

On Linux, if you want to enable IP aliasing for an interface, you can execute a command like:
ifconfig eth0:1.1.4.21 1.1.4.21 netmask 255.255.255.0
On the other hand, if you want to disable IP aliasing, you can execute a command like:
ifconfig eth0:1.1.4.21 down


Apache Exec


The Apache Exec component can be used to execute system commands. [2]

To enable IP aliasing, run exec with URL like:
exec://sh?args=-c+%22ifconfig+eth2%3A1.1.3.21+1.1.3.21+netmask+255.255.255.0%22&timeout=60000
And to disable it, use the following URL:
exec://sh?args=-c+%22ifconfig+eth2%3A1.1.4.21+down%22&timeout=60000
If alias was already set and you want to enable it again, or the alias is disabled and you want to disable it again, you'll get some error message, like
Cannot assign requested address

References


  1. Wikipedia, http://en.wikipedia.org/wiki/IP_aliasing
  2. Apache Camel, http://camel.apache.org/exec.html



Create a Successful Online Store at Bigcommerce! Try it Free Now!

Saturday, January 24, 2015

Camel Exec Command Script | Apache Camel Exec - Run Multiple Commands/Scripts at One Go

Camel Exec Windows Example

You could use the following settings to run multiple executables (including scripts) at one go using the Exec component.
On Windows:
<exec executable="cmd" argument="RAW(/c c:/batch1.bat;&amp;c:/batch2.bat)"/>

Camel Exec Linux Example

On Linux:
<exec executable="sh" argument="-c &quot;cd /product;./executable1;cd /customer;./executable2&quot;"/>
brookstone, free shipping

Camel Exec XML Example

If you use Java code instead of XML, you could simply replace '&' with '&' and '"' with '\"', and make them work.
Another thing I want to mention is that on Linux, it's better to run with './executable1' instead of 'executable1'.
Check more details here.


Create a Successful Online Store at Bigcommerce! Try it Free Now!

Apache Camel Ampersand URL | Apache Camel - Include an Ampersand in an URL

Camel URL Ampersand Issue

Recently I encountered a problem when I was using the Exec component to run multiple Windows batch files at one go.
All my parameters were put in an XML file, so I had something like:
<exec executable="cmd" argument="/c c:/batch1.bat;c:/batch2.bat"/>
However, with these settings, only the first batch file was executed.
After some search, I changed the configuration to
<exec executable="cmd" argument="/c c:/batch1.bat;&amp;c:/batch2.bat"/>
This time Camel complained it did not recognize some parameters (c:/batch2.bat). This was because Camel treats '&' as URL delimiter.

Use RAW  to Escape Ampersand

I managed to solve it by using the syntax RAW:
<exec executable="cmd" argument="RAW(/c c:/batch1.bat;&amp;c:/batch2.bat)"/>

What I want to mention is that RAW must be used to enclose the whole value of a parameter, not a part. So the following does not work:
<exec executable="cmd" argument="/c RAW(c:/batch1.bat;&amp;c:/batch2.bat)"/>

Check more details here.


Create a Successful Online Store at Bigcommerce! Try it Free Now!