You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by "jeevan.koteshwara" <je...@gmail.com> on 2011/09/12 16:10:23 UTC

Calling shell script from Camel

Hi,
    I have a requirement, where I need to call a shell script (for zipping
and unzipping files with associated passwords if any) from the route.

I have chosen exec component to do so. I have seen exec:java or exec:perl to
execute respective java or perl files/scripts. Is there any direct way to
execute the shell script using exec (similar to exex:java or exec:perl etc).
Or do I need to provide the the file path of the shell script to be
executed.

for ex:

from(src).to("exec:/opt/script/compress.sh");

Also, I am using ExecBinding.EXEC_COMMAND_ARGS to pass the arguments
dynamically to the shell script.

Please suggest, is this approach is the best approach or not. Is there any
other solutions available for the same.

Thanks and Regards,
Jeevan Mithyantha. 

--
View this message in context: http://camel.465427.n5.nabble.com/Calling-shell-script-from-Camel-tp4794335p4794335.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Calling shell script from Camel

Posted by Donald Whytock <dw...@gmail.com>.
Looking at the component doc, it looks like what you need is

"exec:D:/Program Files/Cygwin/bin/bash?args=/tmp/exec/scripts/echo.sh"

for your to() URL.

Don

Re: Calling shell script from Camel

Posted by "jeevan.koteshwara" <je...@gmail.com>.
Hi Boday,
            thanks for the suggestion. I have few more doubts here.

I have written few simple shell scripts. I am testing exec stuff from camle
to call these scripts. I installed cygwin in my system. When I tried running
the exec through Camel, was failing with following error.

SEVERE: Caused by: [org.apache.camel.component.exec.ExecException - Unable
to execute command ExecCommand [args=[], executable=D:/Program
Files/Cygwin/bin/bash /tmp/exec/scripts/echo.sh,
timeout=9223372036854775807, outFile=null, workingDir=null,
useStderrOnEmptyStdout=false]]
org.apache.camel.component.exec.ExecException: Unable to execute command
ExecCommand [args=[], executable=D:/Program Files/Cygwin/bin/bash
/tmp/exec/scripts/echo.sh, timeout=9223372036854775807, outFile=null,
workingDir=null, useStderrOnEmptyStdout=false]
	at
org.apache.camel.component.exec.impl.DefaultExecCommandExecutor.execute(DefaultExecCommandExecutor.java:81)
	at
org.apache.camel.component.exec.ExecProducer.process(ExecProducer.java:48)
....
....
Caused by: java.io.IOException: Cannot run program "D:\Program
Files\Cygwin\bin\bash \tmp\exec\scripts\echo.sh": CreateProcess error=3, The
system cannot find the path specified
	at java.lang.ProcessBuilder.start(ProcessBuilder.java:460)
	at java.lang.Runtime.exec(Runtime.java:593)
....
....
Caused by: java.io.IOException: CreateProcess error=3, The system cannot
find the path specified
	at java.lang.ProcessImpl.create(Native Method)
...
...

I have also written a standalone java program, which will directly execute
the same command using Runtime.getRuntime().exec() method, where it executed
perfectly without any errors/exceptions.

Now,I am uncertain, why the similar stuff is failing when I execute through
camel.
E.g.
from("file:/tmp/exec")..to("exec:D:/Program Files/Cygwin/bin/bash
/tmp/exec/scripts/echo.sh");

Anyone, please suggest on this.

Thanks and Regards,
Jeevan Mithyantha.



--
View this message in context: http://camel.465427.n5.nabble.com/Calling-shell-script-from-Camel-tp4794335p4798408.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Calling shell script from Camel

Posted by boday <be...@initekconsulting.com>.
yep, you should be able to call a shell script directly like this...


jeevan.koteshwara wrote:
> 
> Hi,
>     I have a requirement, where I need to call a shell script (for zipping
> and unzipping files with associated passwords if any) from the route.
> 
> I have chosen exec component to do so. I have seen exec:java or exec:perl
> to execute respective java or perl files/scripts. Is there any direct way
> to execute the shell script using exec (similar to exex:java or exec:perl
> etc). Or do I need to provide the the file path of the shell script to be
> executed.
> 
> for ex:
> 
> from(src).to("exec:/opt/script/compress.sh");
> 
> Also, I am using ExecBinding.EXEC_COMMAND_ARGS to pass the arguments
> dynamically to the shell script.
> 
> Please suggest, is this approach is the best approach or not. Is there any
> other solutions available for the same.
> 
> Thanks and Regards,
> Jeevan Mithyantha.
> 


-----
Ben O'Day
IT Consultant -http://consulting-notes.com

--
View this message in context: http://camel.465427.n5.nabble.com/Calling-shell-script-from-Camel-tp4794335p4795990.html
Sent from the Camel - Users mailing list archive at Nabble.com.