Tuesday, June 11, 2013

BASH: Regular Express Extract Substring Samples

Sample 1: download files in html source


#!/bin/bash

inputFile=$1

exampleRegExp=".*href=\"(.*.[:alpha:]{1,4})[\"]{1}.*"
while read line
do

#if [[ $exampleRegExp =~ $line ]]; then
#   echo $line
#fi

if [[ $line =~ $exampleRegExp ]]; then
   #echo $line
   echo ${BASH_REMATCH[1]}
   (cd src; wget http://jcifs.samba.org/src/examples/${BASH_REMATCH[1]} )
fi

done < ${inputFile}


======================================
Data File Sample

<tr><td valign="top"><img src="/icons/unknown.gif" alt="[   ]"></td><td><a href="UrlReader.java">UrlReader.java</a></td><td align="right">18-Oct-2011 15:26  </td><td align="right">1.0K</td></tr>
<tr><td valign="top"><img src="/icons/unknown.gif" alt="[   ]"></td><td><a href="VerifyGuest.java">VerifyGuest.java</a></td><td align="right">18-Oct-2011 15:26  </td><td align="right">896 </td></tr>
<tr><td valign="top"><img src="/icons/unknown.gif" alt="[   ]"></td><td><a href="VerifyIO.java">VerifyIO.java</a></td><td align="right">18-Oct-2011 15:26  </td><td align="right">2.1K</td></tr>
<tr><td valign="top"><img src="/icons/unknown.gif" alt="[   ]"></td><td><a href="VerifyReads.java">VerifyReads.java</a></td><td align="right">18-Oct-2011 15:26  </td><td align="right">2.1K</td></tr>
<tr><td valign="top"><img src="/icons/unknown.gif" alt="[   ]"></td><td><a href="WaitNamedPipe.java">WaitNamedPipe.java</a></td><td align="right">18-Oct-2011 15:26  </td><td align="right">1.1K</td></tr>

Sample 2: Cut information from html source


 #!/bin/bash
#set -x
inputFile=$1

#<h4 class="sect3"><span class="secnum">1.13.1.2</span> Volume Shadow Copy Service (VSS) Writer</h4>

exampleRegExp=".*secnum\">(.*.[0-9]{1,2})<\/span>( .*)<\/h.*>$"
while read line
do

if [[ $line =~ $exampleRegExp ]]; then
      echo ${BASH_REMATCH[1]} ${BASH_REMATCH[2]}fi

done < $inputFile

Sample 3: Grab information from DDL scripts

 #!/bin/bash
#set -x
#  `Place_ID` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'Event ID',

inputFile=$1

regExp=".*\`(.*)\`[ \t](.*)[\(]{1}([0-9]+).*'(.*)'.*{1}"

while read line
do
  if [[ $line =~ $regExp ]]; then
    echo ${BASH_REMATCH[1]} ${BASH_REMATCH[2]} ${BASH_REMATCH[3]} ${BASH_REMATCH[4]}
  fi
done < sql/$inputFile

Sample 4: backslash in source file


 #!/bin/bash
 #set -x
inputFile=$1

#exampleRegExp=".*href=\"(.*.[:alpha:]{1,4})[\"]{1}.*"
exampleRegExp=".*href=\"([0-9]{4})[\\]{1}(.*.pdf)[\"]{1}.*"
#exampleRegExp="[0-9]{4}\\.*.pdf"
while read -r line
do

#if [[ $exampleRegExp =~ $line ]]; then
#   echo $line
#fi

if [[ $line =~ $exampleRegExp ]]; then
   #echo $line
   echo "${BASH_REMATCH[1]}"
   year="${BASH_REMATCH[1]}"
   echo "${BASH_REMATCH[2]}"
   mkdir -p ${year}
   (cd ${year}; wget http://www.people.okanagan.bc.ca/clee/bcssmc/${BASH_REMATCH[1]}/${BASH_REMATCH[2]} )
fi

done < ${inputFile}

Monday, June 10, 2013

RMAN to clean up archivelog and backup

RMAN=/usr2/app/oracle/production/11g/bin/rman $RMAN nocatalog target / < <EOF
crosscheck backup;
crosscheck archivelog all;
delete noprompt expired archivelog all;
delete noprompt expired backup;
delete noprompt obsolete;
EOF


delete noprompt archivelog all;
delete noprompt backup;
 

Friday, June 7, 2013

Thursday, June 6, 2013

SQLPlus: show data only without Header

To show only data in SQLplus and no header or other stuff, enter the following:

SET NEWPAGE 0
SET SPACE 0
SET LINESIZE 80
SET PAGESIZE 0
SET ECHO OFF
SET FEEDBACK OFF
SET VERIFY OFF
SET HEADING OFF
SET MARKUP HTML OFF SPOOL OFF

KSH read line

#!/bin/ksh

fileName=/etc/passwd
 
while IFS=\: read userName homeDirectory
do
 print "$userName 's home directory is $homeDirectory"
done <"$fileName"

Tuesday, June 4, 2013

Oracle: Reconfigure EM after hostname changed.

If the machine name has already been changed

When the ipaddress or hostname of the machine running dbconsole has already been changed, it is necessary to drop the dbconsole manually and create it again afresh using the following steps:-

1) drop the dbconsole repository schema manually following the steps in note:278100.1.  Follow Section A, option 4 "Delete DB Control Repository Objects Manually"

Delete DB Control Repository Objects Manually


Method 1: Drop AQ related objects and DB Console repository object from the SYSMAN schema in quiesce mode:

Run from SQLPLUS as user SYS (as SYSDBA):
SQL> exec DBMS_AQADM.DROP_QUEUE_TABLE(queue_table=>'SYSMAN.MGMT_NOTIFY_QTABLE',force =>TRUE);
SQL> SHUTDOWN IMMEDIATE;
SQL> STARTUP RESTRICT;
SQL> EXEC sysman.emd_maintenance.remove_em_dbms_jobs;
SQL> EXEC sysman.setEMUserContext('',5);
SQL> REVOKE dba FROM sysman;
SQL> DECLARE
CURSOR c1 IS
SELECT owner, synonym_name name
FROM dba_synonyms
WHERE table_owner = 'SYSMAN';
BEGIN
FOR r1 IN c1 LOOP
IF r1.owner = 'PUBLIC' THEN
EXECUTE IMMEDIATE 'DROP PUBLIC SYNONYM '||r1.name;
ELSE
EXECUTE IMMEDIATE 'DROP SYNONYM '||r1.owner||'.'||r1.name;
END IF;
END LOOP;
END;
/
SQL> DROP USER mgmt_view CASCADE;
SQL> DROP ROLE mgmt_user;
SQL> DROP USER sysman CASCADE;
SQL> ALTER SYSTEM DISABLE RESTRICTED SESSION;

Note 1: On some versions (11.1 +), the SYSDBA role is no longer granted to SYSMAN account, so the respective statement may fail. This is not an issue and can be ignored.



2) Delete the dbconsole configuration files manually following the steps in note:278100.1.  Follow Section A, option 2 "Delete DB Control Configuration Files Manually"



Delete DB Control Configuration Files Manually

Remove the following directories from your filesystem:
<ORACLE_HOME>/<hostname_sid>
<ORACLE_HOME>/oc4j/j2ee/OC4J_DBConsole_<hostname>_<sid>

If the database was upgraded, (for example from 10.2.0.3 to 10.2.0.4) then the following directory also needs to be removed from the file system:
<ORACLE_HOME>/<hostname_sid>.upgrade
<ORACLE_HOME>/oc4j/j2ee/OC4J_DBConsole_<hostname>_<sid>.upgrade

3) Ensure that the listener has the correct new hostname/ipaddress
4) Ensure that the hosts file has the correct new hostname/ipaddress
5) Create dbconsole using

emca -config dbcontrol db -repos create.

Changing host names and migrating profiles in WebSphere Application Server

http://www.ibm.com/developerworks/websphere/techjournal/0905_webcon/0905_webcon.html

Oracle 10g and 11g: Clean up Stream Configuration

Remove using package DBMS_STREAMS_ADM.REMOVE_STREAMS_CONFIGURATION
as below

SQL> begin
DBMS_STREAMS_ADM.REMOVE_STREAMS_CONFIGURATION;
end;
/