Chamar shell no forms 10g

Dicas do Oracle Forms Builder - Blocos, Itens, LOV, Canvas, Triggers, comandos, PLL, d2kwutil, FMB, Alert, menus, etc
Responder
s_feitoza
Rank: Estagiário Sênior
Rank: Estagiário Sênior
Mensagens: 10
Registrado em: Qui, 29 Nov 2007 5:04 pm
Localização: São Paulo

Bom dia pessoal..

Estou utilizando o Forms 10g e prescisao chamar alguns Shell´s que esta no Servidor. Tentei utilizar o comando HOST mais o mesmo so faz o form ficar dando loop e não apresenta nada... Consigo chamar os outros form e os reports...
Minha dúvida é como eu deveria chamar esses Shells...

Grato desde já Silvio
Avatar do usuário
dr_gori
Moderador
Moderador
Mensagens: 5024
Registrado em: Seg, 03 Mai 2004 3:08 pm
Localização: Portland, OR USA
Contato:
Thomas F. G

Você já respondeu a dúvida de alguém hoje?
https://glufke.net/oracle/search.php?search_id=unanswered

Procure pela package daemon.
Ela executa coisas no servidor. (infelizmente, não tenho ela aqui)
:-o
Avatar do usuário
dr_gori
Moderador
Moderador
Mensagens: 5024
Registrado em: Seg, 03 Mai 2004 3:08 pm
Localização: Portland, OR USA
Contato:
Thomas F. G

Você já respondeu a dúvida de alguém hoje?
https://glufke.net/oracle/search.php?search_id=unanswered

Tenho sim!
Ta aqui ela, só não sei se é só compilar e já vai funcionar. Talvez tenha que ter algum arquivo no servidor.

Spec

Selecionar tudo

create or replace package daemon as
  /* Executes a non-query sql statement or plsql block.  Arguments:
     command: the sql statement to execute
     timeout: (optional) number of seconds to wait to send or receive a
              message
     Returns the sqlcode after execution of the statement. */
  function execute_sql(command varchar2, timeout number default 10)
    return number;

  /* Executes a system (host) command.  Arguments:
     command: the command to execute
     timeout: (optional) number of seconds to wait to send or receive a
              message
     Returns the value passed to the operating system by the command. */
  function execute_system(command varchar2, timeout number default 10)
    return number;

  /* Tells the daemon listener to exit.  Arguments:
     timeout: (optional) number of seconds to wait to send the message. */
  procedure stop(timeout number default 10);
end daemon;
Body

Selecionar tudo

create or replace package body daemon as

  function execute_system(command varchar2, timeout number default 10)
    return number is

    s number;
    result varchar2(20);
    command_code number;
    pipe_name varchar2(30);
  begin

    /* Use uniqe_session_name to generate a unique name for the return pipe.
       We include this as part of the inital message to the daemon, and it is
       send along the pipe named 'daemon'.  */
    pipe_name := dbms_pipe.unique_session_name;

    /* Send the 'SYSTEM' command to the daemon. */
    dbms_pipe.pack_message('SYSTEM');
    dbms_pipe.pack_message(pipe_name);
    dbms_pipe.pack_message('export GTA=/usr/Gta;'||command);
    s := dbms_pipe.send_message('daemon', timeout);
    if s <> 0 then
      raise_application_error(-20010,
        'Execute_system: Error while sending.  Status = ' || s);
    end if;

    /* Check for the handshake message.  Note that we are now listening on
       the pipe which is unique to this session. */
    s := dbms_pipe.receive_message(pipe_name, timeout);
    if s <> 0 then
      raise_application_error(-20011,
        'Execute_system: Error while receiving.  Status = ' || s);
    end if;

    /* Get the operating system result code, and display it using
       dbms_output.put_line(). */
    dbms_pipe.unpack_message(result);
    if result <> 'done' then
      raise_application_error(-20012,
        'Execute_system: Done not received.');
    end if;

    dbms_pipe.unpack_message(command_code);
    dbms_output.disable;
    dbms_output.enable(1000000000);
    dbms_output.put_line('System command executed.  result = ' ||
                         command_code);
    return command_code;
  end execute_system;


  function execute_sql(command varchar2, timeout number default 10)
    return number is

    s number;
    result varchar2(20);
    command_code number;
    pipe_name varchar2(30);
  begin


    /* Use uniqe_session_name to generate a unique name for the return pipe.
       We include this as part of the inital message to the daemon, and it is
       send along the pipe named 'daemon'.  */
    pipe_name := dbms_pipe.unique_session_name;

    /* Send the 'SQL' command to the daemon. */
    dbms_pipe.pack_message('SQL');
    dbms_pipe.pack_message(pipe_name);
    dbms_pipe.pack_message('export GTA=/usr/Gta;'||command);
    s := dbms_pipe.send_message('daemon', timeout);
    if s <> 0 then
      raise_application_error(-20020,
        'Execute_sql: Error while sending.  Status = ' || s);
    end if;

    /* Check for the handshake message.  Note that we are now listening on
       the pipe which is unique to this session. */
    s := dbms_pipe.receive_message(pipe_name, timeout);
    if s <> 0 then
      raise_application_error(-20021,
        'Execute_sql: Error while receiving.  Status = ' || s);
    end if;

    /* Get the result code from the SQL statement, and display it using
       dbms_output.put_line(). */
    dbms_pipe.unpack_message(result);
    if result <> 'done' then
      raise_application_error(-20022,
        'Execute_sql: Done not received.');
    end if;

    dbms_pipe.unpack_message(command_code);
    dbms_output.put_line('SQL command executed.  sqlcode = ' || command_code);
    return command_code;
  end execute_sql;


  procedure stop(timeout number default 10) is
    s number;
  begin

    /* Send the 'STOP' command to the daemon. */
    dbms_pipe.pack_message('STOP');
    s := dbms_pipe.send_message('daemon', timeout);
    if s <> 0 then
      raise_application_error(-20030,
        'Stop: Error while sending.  Status = ' || s);
    end if;
  end stop;

end daemon;

Um exemplo do seu uso:
(neste caso, envia um email pelo shell)

Selecionar tudo

declare
  ln_daemon number;
begin

  ln_daemon := daemon.execute_system('echo "Ocorreu ERRO na Importação das Faturas! Veja tabela LOG_FATURA!" | mail -s $(hostname)_LOGFATURA bill@microsoft.com'  ,10000 );
end;
s_feitoza
Rank: Estagiário Sênior
Rank: Estagiário Sênior
Mensagens: 10
Registrado em: Qui, 29 Nov 2007 5:04 pm
Localização: São Paulo

Oi boa tarde... Tentei deu erro...

Eu crio essa package no forms ou no Banco? pois o forms não aceita algumas expressões PL/SQL

Replace por exemplo...

Lembrando que estou com forms 10g e acessando um servidor linux para rodar comandos em shells...
Avatar do usuário
dr_gori
Moderador
Moderador
Mensagens: 5024
Registrado em: Seg, 03 Mai 2004 3:08 pm
Localização: Portland, OR USA
Contato:
Thomas F. G

Você já respondeu a dúvida de alguém hoje?
https://glufke.net/oracle/search.php?search_id=unanswered

É uma package de banco!
Ela roda coisas no sistema operacional onde está o ORACLE instalado!
gokden
Rank: DBA Pleno
Rank: DBA Pleno
Mensagens: 264
Registrado em: Dom, 19 Ago 2007 8:18 pm
Localização: Ribeirão Preto - SP
Lucas de Souza

OCA Developer
Analista de sistemas

galera.... to com um erro assim na hora de executar esta package.

Selecionar tudo

ERROR at line 1:
ORA-20011: Execute_system: Error while receiving.  Status = 1
ORA-06512: at "LUCAS.DAEMON", line 61
ORA-06512: at line 1
alguém sabe o porque ??
facc
Rank: Analista Pleno
Rank: Analista Pleno
Mensagens: 104
Registrado em: Qua, 27 Mai 2009 2:37 pm
Localização: Cerquilho / SP

Desculpa ressussitar esse tópico, mas estou tendo o mesmo erro com essa package
Petermann
Rank: Programador Júnior
Rank: Programador Júnior
Mensagens: 18
Registrado em: Seg, 26 Jan 2009 2:26 pm
Localização: Brusque - SC
Alexandre Petermann

Algum sabe aqui quais são os parametros para executar o codigo da package daemon, para o seguinte codigo:

Selecionar tudo

  PROCEDURE EXPORTA_DELPHI IS
  
    ln_daemon number;
  begin
  
    ln_daemon := daemon.execute_system(I:\click_Textil\ceja\Delphi\Delphi_Exportaçao_Dados\P_CEJA.exe);
  
  end;
Avatar do usuário
dr_gori
Moderador
Moderador
Mensagens: 5024
Registrado em: Seg, 03 Mai 2004 3:08 pm
Localização: Portland, OR USA
Contato:
Thomas F. G

Você já respondeu a dúvida de alguém hoje?
https://glufke.net/oracle/search.php?search_id=unanswered

Tem que colocar também o timeout: (no exemplo abaixo, 10000)

Selecionar tudo

declare
  ln_daemon number;
begin

  ln_daemon := daemon.execute_system('echo "Ocorreu ERRO na Importação das Faturas! Veja tabela LOG_FATURA!" | mail -s $(hostname)_LOGFATURA bill@microsoft.com'  ,10000 );
end;
Mas lembre-se que ele roda no servidor ORACLE, não na máquina local do usuário.
Responder
  • Informação
  • Quem está online

    Usuários navegando neste fórum: Nenhum usuário registrado e 5 visitantes