Sponsored Content
Full Discussion: ksh scripting
Top Forums Shell Programming and Scripting ksh scripting Post 302938175 by Chubler_XL on Thursday 12th of March 2015 05:05:18 PM
Old 03-12-2015
Can I suggest a couple of things:

Indent all your if,do,while blocks you will find issues like this much easier

make use of <<-"EOF" when using here-documents

This allows you to indent the EOF and makes your script easier to read. You also don't need to escape dollar ($) symbols as no shell expansion is done.


I believe the here-document starting on line 30 wasn't ended correctly because the EOF was indented.


Here is the corrected and nicely formatted code:

Code:
#! /bin/ksh
#############################################
# Script to delete ODS archived logs from ASM
#############################################
export TIMESTAMP=`date "+%y%m%d_%H%M%S"`
set -a
set -x
SLEEPTIME=1800
date
exec >/users/oracle/Mani/logdel_${TIMESTAMP}.log 2>&1
#############################################################
# DECLARE STREAMS AND NON-STREAMS DATABASES IN THIS ARRAY

#set -A STREAMS_ODS_DB_LIST nwc2 nwd2 nwe2 nwf2 nwo2 nwb2 nwa2 nwk2 nww2 nwt2 nwu2 nwr2 nwx2 nwy2 nwa5 nwc5 nwe3 nwd5 nwe5 nwf3 nwf5 nwh3 nwi3 nwx2 nwj3
set -A STREAMS_ODS_DB_LIST nwb3 nwa2 nwa5 nwb2 nwc2 nwc5 nwd2 nwd5 nwe2 nwe3 nwe5o nwf2 nwf3 nwf5 nwh3 nwi3 nwj3 nwk2 nwo2 nwr2 nwt2 nwu2 nww2 nwx2 nwy2 nwz2 nwk3

function DELNWE5O {
	export ORACLE_HOME=/ora00/app/oracle/product/11.2.0/grid_1
	export ORACLE_SID=+ASM
	export PATH=${ORACLE_HOME}/bin:${PATH}
	DG=`sqlplus -s '/as sysasm' <<-"EOF"
		set pagesize 0 feedback off verify off heading off echo off;
		select NAME from v$asm_client ac ,v$asm_diskgroup ad where ac.GROUP_NUMBER=ad.GROUP_NUMBER and ac.INSTANCE_NAME like 'nwe5o' and NAME like '%ARCH3';
		exit;
	EOF`
	export ORACLE_HOME=/ora01/app/oracle/product/11.2.0/db_1
	export ORACLE_SID=$ORACLE_SID
	export PATH=${ORACLE_HOME}/bin:${PATH}
	LIBPATH=${ORACLE_HOME}/lib
	sqlplus -s '/as sysdba' <<-"EOF"
		SET PAGES 0 LINES 175 HEAD OFF FEED OFF
		spool /users/oracle/Mani/delete_list_ods_nwe5o.sql
		SELECT  --+ NO_MERGE(C)
		'ALTER DISKGROUP ${DG}  DROP FILE '''||R.NAME||'''; '
		FROM DBA_REGISTERED_ARCHIVED_LOG R, DBA_CAPTURE C, V\$ASM_FILE F
		WHERE R.CONSUMER_NAME = C.CAPTURE_NAME
		AND R.NEXT_SCN < C.REQUIRED_CHECKPOINT_SCN
		AND F.FILE_NUMBER = SUBSTR(R.NAME,INSTR(R.NAME,'.',1,1)+1,INSTR(R.NAME,'.',1,2)-INSTR(R.NAME,'.',1,1)-1)
		AND F.INCARNATION = SUBSTR(R.NAME,INSTR(R.NAME,'.',1,2)+1);
		spool off
		EXIT
	EOF
}

# DATABASES NOT IN THE ABOVE LISTS ARE NOT IN ARCHIVELOG MODE
#############################################################
#SLEEPTIME=40
while :; do
	# Delete downstream archivelogs for Streams ODS databases
	echo
	echo "-------------------------------------------------------"
	echo "Deleting Downstream Logs for Streams ODS Databases ...."
	date
	echo "-------------------------------------------------------"
	#rm -f /tmp/delete_list_ods.log
	if [[ ! -z ${STREAMS_ODS_DB_LIST[@]} ]]; then
		echo ${STREAMS_ODS_DB_LIST[@]}
		for ORACLE_SID in `echo ${STREAMS_ODS_DB_LIST[@]}`; do
			if [[ `ps -ef | grep "ora_smon_${ORACLE_SID}" | grep -v 'grep' | wc -l |awk '{ print $1 }'` != 0 ]]; then
				ORAENV_ASK=NO
				export ORACLE_HOME=/ora01/app/oracle/product/11.2.0/db_1
				export ORACLE_SID=$ORACLE_SID
				export PATH=${ORACLE_HOME}/bin:${PATH}
				LIBPATH=${ORACLE_HOME}/lib
				echo "Deleting Logs For SID : ${ORACLE_SID} ...."
				if [[ ${ORACLE_SID} == "nwe5o" ]]
				then
					DELNWE5O
				fi
				sqlplus -s '/as sysdba' <<-"EOF"
					SET PAGES 0 LINES 175 HEAD OFF FEED OFF"
					spool /users/oracle/Mani/delete_list_ods.sql
					SELECT  --+ NO_MERGE(C)
					'ALTER DISKGROUP ${ORACLE_SID}ARCH3  DROP FILE '''||R.NAME||'''; '
					FROM DBA_REGISTERED_ARCHIVED_LOG R, DBA_CAPTURE C, V$ASM_FILE F
					WHERE R.CONSUMER_NAME = C.CAPTURE_NAME
					AND R.NEXT_SCN < C.REQUIRED_CHECKPOINT_SCN
					AND F.FILE_NUMBER = SUBSTR(R.NAME,INSTR(R.NAME,'.',1,1)+1,INSTR(R.NAME,'.',1,2)-INSTR(R.NAME,'.',1,1)-1)
					AND F.INCARNATION = SUBSTR(R.NAME,INSTR(R.NAME,'.',1,2)+1);
					spool off
					EXIT
				EOF
				# If there are no ORA- errors from the previous SQL*Plus
				# command, delete the logs
				if [[ `grep -c 'ORA-' /users/oracle/Mani/delete_list_ods.sql` = 0 ]]; then
					export ORACLE_HOME=/ora00/app/oracle/product/11.2.0/grid_1
					export ORACLE_SID=+ASM
					export PATH=${ORACLE_HOME}/bin:${PATH}
					sqlplus -s '/as sysasm' <<-"EOF"
						spool delete_list_ods.log
						select sysdate from dual;
						spool off
						exit
					EOF
				else
					echo "  ORA- Error"
					cat /users/oracle/Mani/delete_list_ods.sql
				fi
				#rm -f /tmp/delete_list_ods.sql
			fi
		done
	else
	    echo "No Streams ODS databases found"
	fi
	cat delete_list_ods.log
	echo
	echo "++++ Sleeping For ${SLEEPTIME} Seconds ...."
	echo
	sleep ${SLEEPTIME}
done


Last edited by Chubler_XL; 03-12-2015 at 06:10 PM..
These 2 Users Gave Thanks to Chubler_XL For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

KSH Scripting

Will a shell script written in shell for HP/UX run on Solaris? (1 Reply)
Discussion started by: dstaller
1 Replies

2. Shell Programming and Scripting

Need help with KSH scripting

Hi I need to insert a page break into a file based on matching a phrase in the file. :confused: I am doing this with a ksh script on a Unix box. Any help would be greatly appreciated. Thanks (5 Replies)
Discussion started by: scrappycc
5 Replies

3. Shell Programming and Scripting

ksh scripting help

I have the file as below server1 no dr aix 5300-05-03 9119-595 20-18888 yes ftp-eagle server2 no dr aix 5300-05-03 9119-595 20-18888 yes ftp-eagle server3 yes dr aix 5300-05-03 9119-595 20-18888 yes ftp-eagle server4 ... (1 Reply)
Discussion started by: praveenbvarrier
1 Replies

4. Shell Programming and Scripting

ksh scripting help needed.

I am trying to create a script to manipulate numerous file and at first I thought it would be a simple task but at this point i am ready to break my computer! I am new to unix scripting so hopefully someone out there thinks this is super easy and can help me out! A sample of the problem file is... (2 Replies)
Discussion started by: theqcup
2 Replies

5. Shell Programming and Scripting

Problem with Ksh scripting

Hi, Below is the code for my script #!/bin/ksh for file in "file1.txt" "file2.txt" "file3.txt" "file4.txt" do L="$(tail -1 $file)" NUM=${L%%|*} DAT=${L##*|} echo $NUM echo $DAT done Now here,suppose for file1.txt L will have data like 56|06-07-2010 So, it should be (7 Replies)
Discussion started by: fidelis
7 Replies

6. Shell Programming and Scripting

Help with ksh scripting in AIX

I am looking for a script which does the following Script will run daily. 1.It will get snapshot off all filesystems including nfs mounts, automounts and clearcase mounts. 2.Then it will compare new snapshot with the snapshot created in the previous run. 3.If filesystem exists in... (20 Replies)
Discussion started by: saidiya
20 Replies

7. Shell Programming and Scripting

Help needed in ksh scripting

I got a task to do today, I want to write a script for the following 1) Archive log more than 2 days old 2) Number of days the current Archive logs present 3) Total number of archive logs 4) Size of each archive log 5) When was last successful backup happened? Can I get a general script... (8 Replies)
Discussion started by: Rambo
8 Replies

8. Shell Programming and Scripting

help in ksh scripting in aix

Hello gurus I am looking for a script : We need to generate a file list created by user id on a AIX box. Criteria 1: other than userid : dwimpid & aiadmin Criteria 2: Files older than 2 months ( it can be any user id ). File Path to Look: /project and /project1 Thx silu (7 Replies)
Discussion started by: silu
7 Replies

9. Shell Programming and Scripting

help with ksh shell scripting

I want to run a script that checks the env to see if I'm in a test or prod environment. From the command line I enter echo $host and it returns host name and I can tell by the name if I'm in test or prod. When I run the command from a script I get "not found" What's wrong with the script? if ... (2 Replies)
Discussion started by: Bperl1967
2 Replies

10. Shell Programming and Scripting

KSH scripting

Hi Guys, I am trying to learn to script. first I have 2 server, A and B. A with IP 192.168.82.22. B with IP 192.168.82.44. Both with login user admin and password admin. server A will generate a file every day with name gg.log under /app/gg/20171002.log. I wish to write a script to copy the... (7 Replies)
Discussion started by: leecopper
7 Replies
All times are GMT -4. The time now is 11:23 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy