Sunday, January 14, 2007
DBMS_SCHEDULER no Linux
Já postei aqui um exemplo de como executar o DBMS_SCHEDULER no Windows. Agora é a vez do linux.
Primeiro um script que, quando executa, atualiza um arquivo chamado "executou" com a data do momento.
[marcio@luke bin]$ pwd
/home/marcio/bin
[marcio@luke bin]$ cat test_shell.sh
#!/usr/bin/ksh
#
echo `date` >> /tmp/executou
Verifique se o usuário do oracle no sistema operacional tem acesso ao script.
[marcio@luke bin]$ su - oracle
Password:
[oracle@luke ~]$
[oracle@luke ~]$ ~marcio/bin/test_shell.sh
[oracle@luke ~]$ ~marcio/bin/test_shell.sh
[oracle@luke ~]$
[oracle@luke ~]$ cat /tmp/executou
Tue Jan 24 00:03:04 BRST 2006
Tue Jan 24 00:03:05 BRST 2006
[oracle@luke ~]$
Isso significa que o oracle, usuário do sistema operacional dono do oracle 10g da minha instalação tem permissão e
consiguiu executar o script por 2 vezes, gerando o arquivo /tmp/executou com os respectivos horários.
Agora, vamos criar o job para executar de 2 em 2 minutos.
SQL> begin
2 dbms_scheduler.create_job
3 (
4 job_name => 'TEST_SHELL',
5 job_type => 'EXECUTABLE',
6 job_action => '/home/marcio/bin/test_shell.sh',
7 repeat_interval => 'FREQ=MINUTELY; INTERVAL=2',
8 end_date => trunc(sysdate) + 30/24/60,
9 enabled => true,
10 comments => 'Teste para execucao de shell linux'
11 );
12 end;
13 /
PL/SQL procedure successfully completed.
E verificar na user_scheduler_jobs.
SQL> select job_name, run_count, to_char(end_date, 'hh24:mi:ss') end_date,
2 to_char(next_run_date, 'hh24:mi:ss') next_run_date
3 from user_scheduler_jobs
4 /
JOB_NAME RUN_COUNT END_DATE NEXT_RUN
------------------------------ ------------- -------- --------
TEST_SHELL 0 00:30:00 00:18:58
1 row selected.
SQL> /
JOB_NAME RUN_COUNT END_DATE NEXT_RUN
------------------------------ ------------- -------- --------
TEST_SHELL 1 00:30:00 00:20:58
1 row selected.
Ok, rodou o primeiro.
SQL> !cat /tmp/executou
Tue Jan 24 00:18:58 BRST 2006
SQL> /
JOB_NAME RUN_COUNT END_DATE NEXT_RUN
------------------------------ ------------- -------- --------
TEST_SHELL 2 00:30:00 00:22:58
1 row selected.
E agora segue até meu end_date ser alcançado!
SQL> !cat /tmp/executou
Tue Jan 24 00:18:58 BRST 2006
Tue Jan 24 00:20:58 BRST 2006
SQL> /
JOB_NAME RUN_COUNT END_DATE NEXT_RUN
------------------------------ ------------- -------- --------
TEST_SHELL 3 00:30:00 00:24:58
1 row selected.
SQL> !cat /tmp/executou
Tue Jan 24 00:18:58 BRST 2006
Tue Jan 24 00:20:58 BRST 2006
Tue Jan 24 00:22:58 BRST 2006
SQL> /
JOB_NAME RUN_COUNT END_DATE NEXT_RUN
------------------------------ ------------- -------- --------
TEST_SHELL 3 00:30:00 00:24:58
1 row selected.
SQL> /
JOB_NAME RUN_COUNT END_DATE NEXT_RUN
------------------------------ ------------- -------- --------
TEST_SHELL 5 00:30:00 00:28:58
1 row selected.
SQL> !cat /tmp/executou
Tue Jan 24 00:18:58 BRST 2006
Tue Jan 24 00:20:58 BRST 2006
Tue Jan 24 00:22:58 BRST 2006
Tue Jan 24 00:24:58 BRST 2006
Tue Jan 24 00:26:58 BRST 2006
SQL> /
no rows selected
SQL> !cat /tmp/executou
Tue Jan 24 00:18:58 BRST 2006
Tue Jan 24 00:20:58 BRST 2006
Tue Jan 24 00:22:58 BRST 2006
Tue Jan 24 00:24:58 BRST 2006
Tue Jan 24 00:26:58 BRST 2006
Tue Jan 24 00:28:58 BRST 2006
Labels: how to