#!/bin/bash
ORACLE_HOME=/app/oracle/product/10.0.0.0
export ORACLE_HOME
PATH=$ORACLE_HOME/bin:$PATH
export PATH
x=`sqlplus -s abc_USER/password@abcd.pfizer.com <<EOFSQL
select USERNAME, EMAIL, FULL_NAME, user_bdate from sfuser where (trunc(sysdate) -trunc(Last_login))>120 and status = 'Active'
and username not in (select username from columnABC)
and ID not in (SELECT distinct created_by_id FROM audit_entry WHERE (TRUNC(SYSDATE) -TRUNC(date_created)) < 120);
EOFSQL`
echo $x>ash_t.xls
uuencode ash_t.cls ash_t.xls | mail mymailid@abc.com
===============================================================
This is the script that i worked on!
I actually want to avoid SPOOL command.
Sensitive approach coz.. i tried all the possible ways to work on with spool but script iz nt getting executed..
below is the script that i tried earlier
#!/bin/bash
ORACLE_HOME=/app/oracle/product/10.0.0.0
export ORACLE_HOME
PATH=$ORACLE_HOME/bin:$PATH
export PATH
sqlplus -s abc_USER/password@abcd.pfizer.com <<EOFSQL
set feedback off
set verify off
set pagesize 0
set term off
set termout off
set heading off
set echo off
SPOOL user.csv
select USERNAME, EMAIL, FULL_NAME, LAST_LOGIN, DATE,CREATED from sfuser where (trunc(sysdate) -trunc(Last_login))>120 and status = 'Active'
and username not in (select username from scm_authorized_keys)
and ID not in (SELECT distinct created_by_id FROM audit_entry WHERE (TRUNC(SYSDATE) -TRUNC(date_created)) < 120);
SPOOL OFF
---------- Post updated at 06:28 AM ---------- Previous update was at 06:19 AM ----------
I suggest create the sql file and .sh file seprated and call the sql file in .sh file and schedule in crontab for desired time , I'm using the same..
eg:-
user.sh:
ORACLE_HOME=/app/oracle/product/10.0.0.0
export ORACLE_HOME
PATH=$ORACLE_HOME/bin:$PATH
export PATH
CDATE=`date +%d%m%Y`
export CDATE
echo $CDATE
. /home/oracle/.bash_profile
sqlplus abc_USER/password@abcd.pfizer.com @/home/oracle/script/user.sql
user.sql:
clear breaks
clear columns
clear compute
set pagesize 50000
set NEWPAGE 1
set linesize 32767
set colsep ,
set headsep on
set serveroutput on size 1000000 format wrap
set feedback off
set underline off
SPOOL user.csv
select USERNAME, EMAIL, FULL_NAME, LAST_LOGIN, DATE,CREATED from sfuser where (trunc(sysdate) -trunc(Last_login))>120 and status = 'Active'
and username not in (select username from scm_authorized_keys)
and ID not in (SELECT distinct created_by_id FROM audit_entry WHERE (TRUNC(SYSDATE) -TRUNC(date_created)) < 120);
SPOOL OFF
---------- Post updated at 06:44 AM ---------- Previous update was at 06:33 AM ----------
Could you pls temme way to create SQL file? Becoz.. whatever i am familiar with is that.. we need to install some packages before creating it.
If it is working then it would be good for me to go with the same. Becoz its just the basic script.. Going ahead.. i need to make give timer to execute this script.