Executing a shell script with DBMS_SCHEDULER
Hi,
when I execute a shell script with DBMS_SCHEDULER this doesn't works correctly
BEGIN
DBMS_SCHEDULER.create_job
job_name => 'job_AR',
job_type => 'EXECUTABLE',
job_action => '/home/crm/crmdw/AR/start_execution.sh',
enabled => TRUE,
start_date => systimestamp,
repeat_interval => 'FREQ=MINUTELY;INTERVAL=15',
comments => 'Test Job AR'
END;Inside the shell script there is a code who call a Hierarchy of process,
if I executed it manually or with a cron, it works perfectly
but when I execute it with the job that I've described before it's executes
all process at same time and it doesn't work.
What can I do to fix the issue,
any Ideas?
Thanks in advanced...
#!/usr/bin/ksh
#test_dbms_scheduler.ksh
echo $1
echo "I am in Unix"
exit 0
chmod 755 test_dbms_scheduler.ksh
Create or replace procedure test_dbms_scheduler
as
v_text varchar2(255) := 'Parameter passed from Oracle to Unix';
Begin
dbms_output.put_line("I am in Procedure");
dbms_scheduler.create_job
(job_name=>'test_dbms_scheduler',
job_action=>'/usr/bin/test_dbms_scheduler.ksh',
number_of_arguments=>1,
job_type=>'executable',
start_date => SYSDATE,
repeat_interval => 'FREQ=SECONDLY; INTERVAL=1',
enabled=>false,
auto_drop => TRUE,
comments=> 'Run shell-script test_dbms_scheduler.ksh');
dbms_scheduler.set_job_argument_value(job_name =>'test_dbms_scheduler', argument_position => 1, argument_value => v_text);
dbms_scheduler.enable('test_dbms_scheduler');
dbms_output.put_line("I am back in Procedure");
Exception
when others then
dbms_output.put_line(sqlcode||sqlerrm);
end;
set serveroutput on
exec test_dbms_scheduler;
Similar Messages
-
Executing Unix shell scripts with DBMS_SCHEDULER
I have the following Unix shell script create_backup_file.sh:
#!/usr/bin/ksh
/usr/bin/ssh [email protected] /usr/bin/touch/app_home/home/trotestbat/scripts/TRO_batch_complete_`date +%d-%m-%Y-%H%M`
If I execute this from the command prompt it creates the file on the remote server.
I've used dbms_scheduler to try and execute this from Oracle:
BEGIN
SYS.DBMS_SCHEDULER.CREATE_PROGRAM
program_name => 'CREATE_TRO_BACKUP_FILE'
,program_type => 'EXECUTABLE'
,program_action => '/APP/TORPEDO/DTE/SCRIPTS/create_backup_file_tro.sh'
,number_of_arguments => 0
,enabled => TRUE
,comments => NULL
SYS.DBMS_SCHEDULER.CREATE_JOB
job_name => 'DTE.TESTAGAIN'
,start_date => TO_TIMESTAMP_TZ('2010/05/17 16:09:24.710789 +01:00','yyyy/mm/dd
hh24:mi:ss.ff tzh:tzm')
,repeat_interval => NULL
,end_date => NULL
,program_name => 'DTE.CREATE_TRO_BACKUP_FILE'
,comments => NULL
END;
The problem I have is that scheduler executes the shell script and creates the file but it never completes the job. The status of the job is permanently 'RUNNING'. Why is the scheduler not returning a completed status?the "infinite" script is usually caused by a prompt (script pauses for a user input).
Please keep in mind that executing script via scheduler is not the same as manually via prompt.
1. the script runs as ORACLE user ID (or whatever you specified using DBMS_SCHEDULER.create_credential or/and "$ORACLE_HOME/rdbms/admin/externaljob.ora")
2. the environment variables are probably not the same.
My wild guess is that you never ran SSH using "oracle" UID and thus it prompts for permission to add the remote computer’s fingerprint to the user’s ~/.ssh/known_hosts file - since it is a script, it just hangs and waits for input.
Did you try to login to unix box as oracle uid and run the script manually? -
Execute unix shell script using DBMS_SCHEDULER
Hi,
I am trying run to shell script using DBMS_SCHEDULER.
1) I check..nobody user exist on my HP-UX.
2) I check externaljob.ora on (10.2.0.2.0) also..It has an entry..
run_user = nobody
run_group = nobody
3) I created job successfully and enabled it.
begin
DBMS_SCHEDULER.CREATE_JOB
job_name => 'test_unix_script',
job_type => 'EXECUTABLE',
job_action => '/tmp/test.ksh',
start_date => '08-NOV-2006 04:45:16 PM',
job_class => 'DEFAULT_JOB_CLASS',
enabled => TRUE,
auto_drop => FALSE,
comments => 'test_unix_script.'
END;
EXEC DBMS_SCHEDULER.enable('test_unix_script');
4) test.ksh script had -r-xr-xr-x permission.
5) When I checking dba_scheduler_job_run_details view, ADDITIONAL_INFO column display following error messgae.
ORA-27369: job of type EXECUTABLE failed with exit code: No such file or directory
Did I miss anything?
Any help will be appreciated!!
Thanks..My /tmp/test.ksh trying to find database status.
. ~oracle/.profile > /dev/null
db_status=`eval sqlplus -s 'system/passwd@DEV' << EOF
set pagesize 0 feedback off verify off heading off echo off
select status from v\\$instance;
exit
EOF`
echo $db_status > /tmp/db_status_out -
Issue with calling Shell Script using DBMS_SCHEDULER
Hi All,
I am executing a shell script using DBMS_SCHEDULER from APEX web page. Execution part is working fine without any issues.
In my shell script file (abc.sh) I have few oracle sql procedure calls which connects back to same database and that SQL call is not executing some reason, it not giving any errors.
Inside my shell script code looks like this.
sqlplus -silent $USER/$PASSCODE@$SCONNECT > /dev/null <<END
set pagesize 0 feedback off verify off heading off serveroutput on
echo off linesize 1000
WHENEVER SQLERROR EXIT 9
BEGIN
dbms_output.enable(1000000);
do_enable_cons();
dbms_output.disable;
END;
spool off;
exit;
END
When I run this shell script file from backend it works fine now issues.
Is there any restrictions in executing sql code using DBMS_SCHEDULER? Any ones help is much appreciated.
-Regardsjames. wrote:
Thanks you sb and Sybrand . It is problem with environment variables. After running .bash_profile in the beginning of the shell script, it is working fine.
One issue is when I check the process it is showing two entries with two different process id's.
The command I used
ps -ef | grep <my script> is COPY & PASTE broken for you?
any reason why you did not show us EXACTLY was produced by OS command above?
>
Is it something wrong with my code or is it normal? Is it really executing two times ?
-Regards
bcm@bcm-laptop:~$ sqlplus user1/user1
SQL*Plus: Release 11.2.0.1.0 Production on Fri Jul 20 15:14:15 2012
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
15:14:15 SQL> !ps -ef | grep sqlplus
bcm 24577 1903 1 15:14 pts/0 00:00:00 sqlplus
bcm 24579 24577 0 15:14 pts/0 00:00:00 /bin/bash -c ps -ef | grep sqlplus
bcm 24581 24579 0 15:14 pts/0 00:00:00 grep sqlplus
15:14:23 SQL> how many different copies of "sqlplus" running on my laptop based upon actual output above? -
Error executing shell script using dbms_scheduler
I have a job running which executes a shell script,which fails with following error :
SQL> SELECT additional_info
2 FROM user_scheduler_job_run_details
3 WHERE log_date = (SELECT MAX (log_date)
4 FROM user_scheduler_job_run_details);
ADDITIONAL_INFO
ORA-27369: job of type EXECUTABLE failed with exit code: No such file or directory
STANDARD_ERROR="mkdir: Failed to make directory "/export/home/bwsolaris/abc"; Permission denied"
This are contents of my shell script
#!/bin/ksh
/bin/mkdir /export/home/bwsolaris/abc
Can anyone suggest me some way out of it?
Thanks in advance!!!Does oracle still creates a user nobody"nobody" is a "standard" Unix/Linux lowly privileged user, which is used by DBMS_SCHEDULER by default.
You should change permissions on /export/home/bwsolaris, e.g.
$ chmod 777 /export/home/bwsolaris
or use a different directory, where everyone has access, for example /tmp.
Or take a look at Metalink Note:391820.1 - Scheduled Job Running Shell Script Fails With ORA-27369 -
Privilege problem on DBMS_SCHEDULER execute linux shell script
Hello, everybody,
I'm a beginner on oracle development , recently , I use DBMS_SCHEDULER to execute linux shell script so that I can transmit files to another ftp server . The problem is , I can't use ordinary user to execute this shell ,but must use sys user , or the procedure will show error : Permission Denied;
I can't change the files' privillege that need to transmit.
I had tried these method,but no use:
1. grant all privillege to user;
2. change the privillege of shell and it's direcotry;
3. use full path in shell;
I hope someone could help me solve this problem , thank you!
the error code :
STANDARD_ERROR="ftp: local: test20121221173852: Permission denied
ftp: local: test20121221173953: Permission denied
ftp: local: test20121221174052: Permission denied
ftp: local: test20121221174153: Permission denied"My /tmp/test.ksh trying to find database status.
. ~oracle/.profile > /dev/null
db_status=`eval sqlplus -s 'system/passwd@DEV' << EOF
set pagesize 0 feedback off verify off heading off echo off
select status from v\\$instance;
exit
EOF`
echo $db_status > /tmp/db_status_out -
Problem with the run_job,shell script with sqlldr
Hi Gurus,
I Created a job which calls the shell script and i understood from the other posting this job is going to execute with nobody,
I had done the below testing
Test 1) Shell script calls the SQL file, this SQL file executes the procedure.
Test 2) Shell script calls the sqlldr command.
When i execute the Test cases with , dbms_scheduler Run_job procedure, Test1 is success but Test2 was failed
When i execute the Test cases with, logging into box with owner of the shell & both test cases are successful.
Parent folder & Shell files are given with 777 permissions. & the Oracle db is version 10.2.0.1.0.
Error:
STANDARD_ERROR="SQL*Loader-522: lfiopn failed for file (*.log)"
Please provide me your inputs its bit urgent Thanks a lot for your help.
Edited by: 926769 on May 23, 2012 2:27 PMFirst of all let's look at your environment ... a totally unpatched version of software that is so old it is in desupport mode. You should upgrade to a fully supported version but, if you can't, at least to 10.2.0.5.
That said without seeing any of your code, or a listing showing permissions on the directory and files, there is insufficient information from which to help you.
Please post ALL information required for us to understand what you are doing an your environment.
But before I decided that NOBODY was doing anything ... I'd shell out to the server from SQL*Plus using the HOST command and verify that permissions are as you believe them to be. There is every reason to believe SQL*Loader is having an issue with your file as identified. -
How to execute unix shell script in webdynpro?
hi all,
We have some iquirement of executing script in unix.If anyone know How to execute unix shell script in webdynpro?
best regard
reefishRee,
1. Find SSH client for windows, then execute SSH with Runtime.exec() on local host with arguments like remote host, auth, command to execute etc.
2. Get SSH client in Java and execute SSH commands on remote host using pure Java API.
Don't ask me for links, Google works today, I checked this
Valery Silaev
SaM Solutions
http://www.sam-solutions.net -
Terminal is trying to auto-execute a shell script
I can no longer use Terminal because every time I try to start it, it automatically runs a shell script I used to have on my desktop and then immediately says "[Process Completed]." I'm not sure how exactly I got it to do this... as far as I know all I did was execute the shell script by associating it with Terminal and double clicking it... but now I can't create a new shell without it automatically attempting to execute it. Please help!
Thanks,
Michaelnevermind... found this http://www.starglider.net/MacOS_X/Terminal-ExecutionString.html
Apparently I'm not the only one who's made this incredibly aggravating mistake -
How to execute power shell script file inside DSC script resource
Hi,
How to execute /call powershell scirpt file inside DSC script resource , some thing like below and capture the status of execution.
Node $AllNodes.NodeName
Script ExecuteSQLDeploy
#SetScript = {powershell.exe .\SQLDeploy.ps1 "param1" "param2" "param3" "param4" "param5" }
#TestScript= {powershell.exe .\SQLDeploy.ps1 "param1" "param2" "param3" "param4" "param5 }
#GetScript= { return $true;}
BasawarajThanks for reply.
Now i am able to execute the power shell script with DSC. I am getting no error when i run , but the script logic wrote inside ( deploying sql incremental changes ) not working . I am using SQLCMD in the powershell script to deploy sql
changes . Can you please elaborate on "script is compatible with DSC" , the script
should not contain write-host cmdlet.... etc something like that.
Copying recursively from ****************************** to ************************** succeeded.
Perform operation 'Invoke CimMethod' with following parameters, ''methodName' = SendConfigurationApply,'className' = MSFT_DSCLocalConfigurationManager,'namespaceName' = root/Microsoft/Windows/DesiredStateConfiguration'.
An LCM method call arrived from computer ************ with user sid **********************************************
[V-BAKANT]: LCM: [ Start Set ]
[V-BAKANT]: LCM: [ Start Resource ] [[Script]ExecuteSQLDeploy]
[V-BAKANT]: LCM: [ Start Test ] [[Script]ExecuteSQLDeploy]
[V-BAKANT]: LCM: [ End Test ] [[Script]ExecuteSQLDeploy] in 0.1110 seconds.
[V-BAKANT]: LCM: [ Start Set ] [[Script]ExecuteSQLDeploy]
[V-BAKANT]: LCM: [ End Set ] [[Script]ExecuteSQLDeploy] in 0.3010 seconds.
[V-BAKANT]: LCM: [ End Resource ] [[Script]ExecuteSQLDeploy]
[V-BAKANT]: LCM: [ End Set ]
[V-BAKANT]: LCM: [ End Set ] in 0.8810 seconds.
Operation 'Invoke CimMethod' complete.
Time taken for configuration job to complete is 0.923 seconds
Basawaraj -
Execute process (shell script) under different user
Hi,
is it possible to use the ProcessBuilder oder .exec()-method to execute a shell script under a JVM-different user? I need to start shell scripts for different system users and I don't want to use SUDO or a wrapper script to switch to the required user. I would like to define the user at java level. Is this possible?
Best regards,
Thomaslooking for something like this too.
currently i am relying on a script in which i have to set the user as:
"su username -c java_program"
the problem with this approach is that if youre not running as root, then su asks for a password, thereby halting execution. (tried input redirects and here-docs, (some popular linux tricks), they did not work)
so you have to be root for the script option to work.
if anyone can suggest a more "java based" way of executing a process as a different user , thatll be awesome. -
Executing a shell script from a java program
Hi,
I'm facing a problem while executing a shell script from a jsp page.
I'm using exec() function.
It's working fine for single statement scripts.But if the script consists of any database processing and some other processing statements,it's not returning the correct exit status of the process.
Will u please help me in this.
If there is any other ways to execute a shell script from a jsp page other than Runtime.exec().If so let me know.
Thanks in advance.I think this shud workMaybe - but it is wrong! Why do you create aReader
and then read bytes which are turned into a String
without worrying about whether or not the bytes area
String and without worrying about the character
encoding if the bytes do represent characters and
without worrying about how many bytes wereactually
read.
Also, both you and the OP should read, digest and
follow the advice given in
http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-
traps.htmlI dont care if it is wrong. This code works for me.
We are here to solve problems not to find which post
is wrong.It is wrong! You are posting bad advice that is very wrong! It may work for you but it is wrong in general! WRONG WRONG WRONG.
If you have a solution then post it I did post a solution! The reference I gave will explain to you and the OP exactly how it should be done.
rather then
posting rude comments.I was not rude! I was explaining just some of what was wrong! -
Executing a shell script from a jsp page
Hi,
I'm facing a problem while executing a shell script from a jsp page.
I'm using Runtime.exec() function.
It's working fine for single statement scripts.But if the script consists of any database processing and some other processing statements,it's not returning the correct exit status of the process.
Will u please help me in this.
If there is any other ways to execute a shell script from a jsp page other than Runtime.exec() like RMI etc,.If so let me know.
Thanks in advance.Hello,
It's hard to help you but what you can do is listening to the outputs of your script, you should read the output stream and error stream and send them to the default console.
Check this excellent article : http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html?page=4
Best regards,
Olivier. -
Error while executing unix shell script from java program
Hi All,
I am trying to execute unix shell script from a java program using Runtime.execute() method by passing script name and additional arguments.
Code snippet :
Java Class :
try{
String fileName ="test.ksh";
String argValue ="satish"; // value passed to the script
String exeParam = "/usr/bin/ksh "+fileName+" "+argValue;
Process proc = Runtime.getRuntime().exec(exeParam);
int exitValue = proc.waitFor();
sop("Exit Value is : "+exitValue);
catch(Exception e)
e.printStackTrace();
}Test.ksh
export -- application realated paths..
nohup abc.exe 1> test.log 2>&1;
$1
exit.By running the above java class , i am getting exit Value: 139 and log file test.log of 0 bytes.
when i am running the same command (/usr/bin/ksh test.ksh satish) manually, it's calling abc.exe file successfully
and able generate the logs properly.
Pls let us know where exactly i am stuck..
Thanks in advance,
Regards,
SatishHi Sabre,
As per the guidelines provided by the article, i had done below changes..
InputStream is = null;
InputStreamReader iStreamReader = null;
BufferedReader bReader = null;
String line = null;
try{
String fileName ="test.ksh";
String argValue ="satish"; // value passed to the script
String exeParam = "/usr/bin/ksh "+fileName+" "+argValue;
Process proc = Runtime.getRuntime().exec(exeParam);
is = proc.getErrorStream();
iStreamReader = new InputStreamReader(is);
bReader = new BufferedReader(iStreamReader);
System.out.println("<ERROR>");
while((line = bReader.readLine()) != null)
System.out.println("Error is : "+line);
System.out.println("</ERROR>");
int exitValue = proc.waitFor();
sop("Exit Value is : "+exitValue);
catch(Exception e)
e.printStackTrace();
Now , it's showing something like..
<ERROR>
</ERROR> -
How to execute unix shell script from Java ...
Hi,
Anyone know how to execute unix shell script from Java?
Suppose I have several shell scripts written in perl or tcl or bash.
I just want to catch the output of that script.
Is there any ready to use module/object for this?
Please let me know, this is quite urgent for my study assigment.
Thanks in advance,
Regards,
meLook up Runtime.exec()
Maybe you are looking for
-
Accessing page/session items in a stored procedure callout from javascript
Hi I am tryin to popup a window with some contents using a javascript by passing an URL to it where URL is a stored procedure callout like <schema>.SP_myproc?p_key=id. My question is whether i can access the apex page items in a session inside the st
-
Steps to create a custom UI control in mobile 7.1 ?
Hello Arvind , What exactly you mean by signature pad here? I understood that you want many custom controls in your view. For this , to start off , you need to create one custom control dc first. And then you can re use the same for any number of cu
-
No orageneric9 in java.library.path on Win2000
I have installed Instant Client on Win2000 by creating a directory, unzipping the archive to it, and adding it to my path. I get an UnsatisfiedLinkError when I try to connect to the database. "Exception in thread "main" java.lang.UnsatisfiedLinkError
-
Dear friends, In IDES, i have created the project and when iam releasing ,PRs will be creating, While creating PR Iam getting the following message. " Custom field mandatory" And PRs are not creating. Pl.suggest. Regards, Canand
-
Hi Im developing an add-on for Sap-Business one 2005. Is there a way to find out the current Patch-Level and Service Pack? I need to know that for checking if the right version of SAP is installed. If not I dont want to load the Add-On. Database-Ve