Sunday, October 12, 2014

ORACLE: Database Links

Creating a Database Link

create database link [LINK_NAME] connect to [USER_ID] identified by [PASSWORD] using '[TNS_NAME]';

example

RDB=((DESCRIPTION...)
create database link RDB_LINK connect to RDB identified by RDB_USER using 'RDB';

ORACLE: Generating CSV output

CSV output to file

set linesize 130
set pagesize 0
set echo off
set wrap off
set heading off

-- get databases users
-- output to file in the same directory as where you have opened SQL*Plus
spool database_users.csv
select u.user_id || ',' || u.surname || ',' || u.forenames
from user u,
where LOWER(u.user_id) like '%a%'
spool off

BASH - Archiving Directories

Archive Directories

#!/bin/bash
# Loop through all directories within the current directory
# tar and gzip all files into a single tarball file
for dir in *
do
    if [ -d "${dir}" ] then
        echo "archiving ${dir} with tar -zcvf"
        echo "tar -zcvf \"${dir}\".tar.gz \"${dir}\""
        dest=`echo ${dir} | tr -t '[ ]' '[_]'`
        echo "dest is now ${dest}"
        tar -zcvf "${dest}".tar.gz "${dir}"
        rm -rf "${dir}"
    fi
done

Perl RegEx: Updating files


Using the Perl Interpreter to update a single file

perl -p -i -e 's{^([^\b\w\t]*)(.*)(openApplication)([^>]*)(.*) Form Menu(.*)$}{\1\2\3\4}' $APACHE_DOCS/$APP_URI/index.html


Using xargs to pass command line parameters to perl

cd /usr/local/adobe/central/

egrep -ir csr00001 * | cut -d: -f1 | xargs perl -p -i -e 's/csr00001/$ENV{HOSTNAME##.*}/g'