1

I want to create a simple job who have to execute this shell command:

echo some_text > 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=>false);
exec dbms_scheduler.set_job_argument_value('write_file',1,'text > /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 > /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 > /tmp/file".

So I tried with multiples arguments:

exec dbms_scheduler.create_job('write_file','executable','/bin/echo',3,auto_drop=>false);
exec dbms_scheduler.set_job_argument_value('write_file',1,'text');
exec dbms_scheduler.set_job_argument_value('write_file',2,'>');
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 > $2?

1 Answer 1

1

I found a patch to this problem. The idea is to create a bash file:

#!/bin/sh
echo $1 > $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=>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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.