Create a job from dbms_scheduler with stream redirection? I want to create a simple job who have to execute this shell command:

echo some_text &gt; some_file


The attributes some_text and some_file can change between two calls to run_job so I need to use set_job_argument_value procedure.

Here is my code:

exec dbms_scheduler.create_job('write_file','executable','/bin/echo',1,auto_drop=&gt;false);
exec dbms_scheduler.set_job_argument_value('write_file',1,'text &gt; /tmp/file');
exec dbms_scheduler.run_job('write_file');


I begin by creating the job who will execute the echo command. This job will take only argument : text &gt; /tmp/file.
When I run my job, the procedure works fine but my file is not created. It's like the procedure runs this command: /bin/echo "text &gt; /tmp/file".

So I tried with multiples arguments:

exec dbms_scheduler.create_job('write_file','executable','/bin/echo',3,auto_drop=&gt;false);
exec dbms_scheduler.set_job_argument_value('write_file',1,'text');
exec dbms_scheduler.set_job_argument_value('write_file',2,'&gt;');
exec dbms_scheduler.set_job_argument_value('write_file',3,'/tmp/file');
exec dbms_scheduler.run_job('write_file');


Same output and no file created.

So, is it possible to specify the standard input? Or to use this kind of job_action: /bin/echo $1 &gt; $2?
I found a patch to this problem. The idea is to create a bash file:

#!/bin/sh
echo $1 &gt; $2


And now, you can create and run your job:

exec dbms_scheduler.create_job('write_file','executable','/usr/bin/oracle/transfer',2,auto_drop=&gt;false);
exec dbms_scheduler.set_job_argument_value('write_file',1,'some_text');
exec dbms_scheduler.set_job_argument_value('write_file',2,'/tmp/some_file');
exec dbms_scheduler.run_job('write_file');


And you can see the result:


$ cat /tmp/some_file
some_text