Category Archives: Unix

crontab examples

* * * * * command to be executed
– – – – –
| | | | |
| | | | +—– day of week (0 – 6) (Sunday=0)
| | | +———- month (1 – 12)
| | +————— day of month (1 – 31)
| +——————– hour (0 – 23)
+————————- min (0 – 59)

Examples for Linux, Solaris, Ubuntu:

# Export everyday at 8:pm
0 20 * * * /…/export_db.sh 1>/dev/null 2>&1

# Export monday to saturday at 01:am
0 1 * * 1-6 /…/export_db.sh 1>/dev/null 2>&1

# Automatique restart of oem agent at 07:00am 10:am 01:pm 03:pm
0 07,10,13,15 * * * /…/agent_restart.sh

#Refresh once a month
30 22 1 * * /…/refresh.sh> /tmp/refesh.log

# Run a script every 10 minutes and between 8am and 10pm (On Linux you can use */10 notation instead of 0, 10, 20…)
0,10,20,30,40,50 8-22 * * * /…/check_db.ksh 1>/dev/null 2>&1

If you want to generate your own cron job, check this useful tool:
http://www.generateit.net/cron-job/

oracle.xml

###########################################################
# Creator: Cyrille Modiano
# Created: 2011/24/02
# Compatible: Solaris update 6 and higher
###########################################################
#
# An example of SMF file: Service Management Facility
# Replacement of /etc/init.d/oracle file for Solaris 10 Update 6 and higher
# Folder: /var/svc/manifest/application/database
# Variables to change: user, exec
#
###########################################################
 





  
    
    

    
        
    
	
    
      
        
      
    

    
      
        
      
    

   

Move db to another host (scp, rename)

REM ################################################
REM # Creator: Didier Vince
REM # Created: 2009/10/01
REM # Name: MoveDB.sql
REM ################################################
REM #
REM # Compatible: Oracle 9i 10g 11g
REM #
REM ################################################
REM #
REM # Move DB to a new machine
REM # 1:  creates scp commands for all the db files (but no init, spfile)
REM # 2:  renames files to our standard
REM #
REM ################################################

define newmachine="&1"

SET ECHO OFF NEWP 0 SPA 0 PAGES 0 FEED OFF HEAD OFF TRIMS ON TAB OFF SERVEROUT OFF VER OFF

undefine direPos dataPos redoPos miroPos
col direPos new_value direPos

set termout off
select instr(b.name,'/',-1,1) + 1 as direPos from v$tablespace a, v$datafile b where a.ts#=b.ts# and a.name='SYSTEM'
/

define dataPos=&direPos
define redoPos=&direPos+8
define miroPos=&direPos+7

undefine iname
col iname new_value iname

select instance_name as iname from v$instance
/

set lines 254 pages 0
spool Copy&iname.FilesTo&newmachine..sh
prompt exit
select 'scp ' || name || ' oradba@&newmachine.:/oracle/bases/&iname./datafile/' || substr(name,&dataPos.) from v$datafile order by ts#
/
select 'scp ' || name || ' oradba@&newmachine.:/oracle/bases/&iname./work/' || substr(name,&dataPos.) from v$tempfile
/
select 'scp ' || member || ' oradba@&newmachine.:/oracle/bases/&iname./rlm1/' from v$logfile where member like '%/redolog/%'
/
select 'scp ' || member || ' oradba@&newmachine.:/oracle/bases/&iname./rlm2/' from v$logfile where member not like '%/redolog/%'
/
select 'scp ' || name || ' oradba@&newmachine.:/oracle/bases/&iname./controlfile/' from v$controlfile
/
select 'scp ' || name || ' oradba@&newmachine.:/oracle/bases/&iname./rlm1/' from v$controlfile
/
select 'scp ' || name || ' oradba@&newmachine.:/oracle/bases/&iname./rlm2/' from v$controlfile
/
spool off

spool Rename&iname.Files.sql
prompt exit
select 'Alter database rename file ''' || name || ''' to ''/oracle/bases/&iname./datafile/' || substr(name,&dataPos.) || ''';' from v$datafile order by ts#
/
select 'Alter database rename file ''' || name || ''' to ''/oracle/bases/&iname./work/' || substr(name,&dataPos.) || ''';' from v$tempfile
/
select 'Alter database rename file ''' || member || ''' to ''/oracle/bases/&iname./rlm1/' || substr(member,&redoPos.) || ''';' from v$logfile  where member like '%/redolog/%'
/
select 'Alter database rename file ''' || member || ''' to ''/oracle/bases/&iname./rlm2/' || substr(member,&dataPos.) || ''';' from v$logfile where member not like '%/redolog/%'
/
spool off
quit

cpu_apply_Mass.sh

#!/usr/bin/ksh
# SCRIPT: cpu_apply_Mass.sh
################################################
# Creator: Yoann Mainguy
# Update: Vincent Fenoll
# Created: 2009/01/01
# Compatible: 10g 11g
################################################
#
# Apply cpu patch on several Oracle databases
# using a for loop
#
################################################

for NO_SID in SID1 SID2 SID3
do
export ORACLE_SID=$NO_SID
export ORAENV_ASK=NO
. oraenv
echo ”
set echo off pages 1000 lines 1000
startup
select instance_name from v\$instance;
@?/rdbms/admin/catbundle cpu apply
@?/rdbms/admin/utlrp
” | sqlplus -s “/ as sysdba” > /tmp/$ORACLE_SID.log &
done

################################################
#
# Recompile views if needed
#
################################################

for NO_SID in SID1 SID2 SID3
do
export ORACLE_SID=$NO_SID
export ORAENV_ASK=NO
. oraenv

#VALUE=`sqlplus -s “/ as sysdba” < /tmp/RECOMP_$ORACLE_SID.log &
#else
# echo “Views already compiled for this database” > /tmp/RECOMP_$ORACLE_SID.log &
#fi
done

Duplicate db using Shell & RMAN

# Author: Vincent Fenoll another Oracle DBA Montreal

#!/usr/bin/ksh
# SCRIPT: duplicate_db_from_time.sh
################################################
#
# Created: 2009/01/01
# Compatible: Oracle 8i 9i 10g 11g
#
################################################
#
# Duplicate database using rman
#
################################################
#
# PRE-REQUISITES:
#    * Instance: NOMOUNT
#    * local variables setted
#    * Oracle variables setted: log_file_name_convert, db_file_name_convert
#
# EXAMPLE:    ./duplicate_db_from_time.sh sys/***@OLDBASE rman/***@rman "08-03-2009 06:16:49″ host_source
#
# Please modify with your value  :      duplicate target database to NEWBASE
#
################################################


if [ "$ORACLE_HOME" = "" ]; then
        echo "Erreur: ORACLE_HOME must be defined"
        exit 1
fi

if [ "$1" = "" -o "$2" = "" -o "$3" = "" -o "$4" = "" ]; then
        echo "Synt: $0 [connect_target] [connect_rmancatalog] [date=DD-MM-YYYY HH24:MI:SS] [server_source_name]"
        exit 1
fi

export NLS_DATE_FORMAT="DD-MM-YYYY HH24:MI:SS"

$ORACLE_HOME/bin/rman target $1 rcvcat $2 auxiliary / << EOF run { set until time "to_date('$3', 'DD-MM-YYYY HH24:MI:SS')"; allocate auxiliary channel t1 type 'SBT_TAPE'; -- If using Networker send 'NSR_ENV=(NSR_SERVER=networkerxxx, NSR_DATA_VOLUME_POOL=FULLxxx, NSR_CLIENT=$4)'; set command id to 'rman_duplicate_from_time'; duplicate target database to NEWBASE NOFILENAMECHECK; release channel t1; } exit; EOF egrep "RMAN-|ORA-" /tmp/resto_rman_$$.log > /dev/null
  if [ $? -eq 0 ]
  then
    return 12
  fi

  return 0