nohup sql
 

 

Eseguire una sessione sql in nohup

Shell che apre una sessione SQL e lancia uno specifico script in nohup, quindi restituisce l'uso della macchina all'utente dopo il lancio stesso  (Avremo quindi il prompt lampeggiante e potremmo controllare che lo script stesso è attivo tramite il comando < ps > senza parametri)

 

lancia_sql_nohup.sh

#!/usr/bin/ksh

if [ $# -ne 3 ]
then
echo "Usage : $0 <user> <password> <query_name>"
echo "Example : $0 guido passwd can_archivio.sql"
exit 1
fi

user=$1
passwd=$2
query_name=$3

lancia_sqlplus() {
nohup sqlplus /nolog << EOF > $log_file
connect $user/$passwd@PID;
@$1;
exit;
EOF
}

log_file="./log/"$query_name".log"

lancia_sqlplus $query_name &

ps -fe | grep sqlplus | grep 'utenteUnix'
ps -f


****************************** can_archivio.sql *******************************************

-- script sql che viene lanciato dalla shell lancia.sh

set serveroutput on;
var errore_finale number;
var numero_righe number;
begin
:errore_finale :=0;
commit;
end;
/


WHENEVER SQLERROR EXIT 1
declare
--numero_righe :=0;
errore number :=0;
othererror EXCEPTION;
begin

errore :=0;

DELETE FROM inventario

--se invece di cancellare volessimo solo visualizzare dovremmo scrivere:
--dbms_output.put_line ('NUMERO_RIGHE=['||:numero_righe||']....');
--select count(*) into :numero_righe FROM inventario
--la clausola <into> è obbligatoria per per funzioni che ritornano informazioni

WHERE (file_name='PREVENTIVI.P051024.001'
OR file_name='CONSUNTIVI.P051024.003')
AND record_type='ARCHIVIATO'
;
if (sqlcode <> 0) then
errore:=1;
end if;
if errore = 0 then

--dbms_output.put_line ('.... NUMERO_RIGHE=['||:numero_righe||']');

dbms_output.put_line('****** Operazione terminata con successo ******');
commit;
else
raise othererror;
end if;

EXCEPTION
WHEN othererror THEN
dbms_output.put_line(SQLERRM);
ROLLBACK;
BEGIN
:errore_finale :=1;
COMMIT;
END;
END;
/
Quit :errore_finale
/
 

--## N.B.
--## i commenti negli script Unix sono rappresentati dal simbolo <#>cancelletto
--## mentre nelle shell SQL dal simbolo <->trattino

 

   

                                                                                                     

appunti italiani