Pythian Blog: Technical Track

How to simplify automation: using environment variables

Automation does not have to be complex and can be as easy as using environment variables. I have blogged about similar topics: Simplify Oracle critical patch updates using simple configurations The objective is to copy the last five trail files for each GoldenGate processes from source to destination. Here are high level steps:
Copy files (rt*) to new destination:
 1. export OLD_DIRDAT=/media/patch/dirdat
 2. export NEW_DIRDAT=/media/swrepo/dirdat
 3. export TRAIL_PREFIX=rt*
 5. ls -l $NEW_DIRDAT
 6. ls $OLD_DIRDAT/$TRAIL_PREFIX | head -5
 7. ls $OLD_DIRDAT/$TRAIL_PREFIX | tail -5
 8. cp -fv $(ls $OLD_DIRDAT/$TRAIL_PREFIX | tail -5) $NEW_DIRDAT
 9. ls -l $NEW_DIRDAT/*
 
 Copy files (jk*) to new destination:
 export TRAIL_PREFIX=jk*
 Repeat steps 5-9
 
DEMO:
[vagrant@racnode-dc1-1 ~]$ export OLD_DIRDAT=/media/patch/dirdat
 [vagrant@racnode-dc1-1 ~]$ export NEW_DIRDAT=/media/swrepo/dirdat
 [vagrant@racnode-dc1-1 ~]$ export TRAIL_PREFIX=rt*
 [vagrant@racnode-dc1-1 ~]$ ls -l $NEW_DIRDAT
 total 0
 [vagrant@racnode-dc1-1 ~]$ ls $OLD_DIRDAT/$TRAIL_PREFIX | head -5
 /media/patch/dirdat/rt01
 /media/patch/dirdat/rt02
 /media/patch/dirdat/rt03
 /media/patch/dirdat/rt04
 /media/patch/dirdat/rt05
 [vagrant@racnode-dc1-1 ~]$ ls $OLD_DIRDAT/$TRAIL_PREFIX | tail -5
 /media/patch/dirdat/rt06
 /media/patch/dirdat/rt07
 /media/patch/dirdat/rt08
 /media/patch/dirdat/rt09
 /media/patch/dirdat/rt10
 [vagrant@racnode-dc1-1 ~]$ cp -fv $(ls $OLD_DIRDAT/$TRAIL_PREFIX | tail -5) $NEW_DIRDAT
 ‘/media/patch/dirdat/rt06’ -> ‘/media/swrepo/dirdat/rt06’
 ‘/media/patch/dirdat/rt07’ -> ‘/media/swrepo/dirdat/rt07’
 ‘/media/patch/dirdat/rt08’ -> ‘/media/swrepo/dirdat/rt08’
 ‘/media/patch/dirdat/rt09’ -> ‘/media/swrepo/dirdat/rt09’
 ‘/media/patch/dirdat/rt10’ -> ‘/media/swrepo/dirdat/rt10’
 [vagrant@racnode-dc1-1 ~]$ ls -l $NEW_DIRDAT/*
 -rwxrwxrwx 1 vagrant vagrant 0 Feb 20 16:58 /media/swrepo/dirdat/rt06
 -rwxrwxrwx 1 vagrant vagrant 0 Feb 20 16:58 /media/swrepo/dirdat/rt07
 -rwxrwxrwx 1 vagrant vagrant 0 Feb 20 16:58 /media/swrepo/dirdat/rt08
 -rwxrwxrwx 1 vagrant vagrant 0 Feb 20 16:58 /media/swrepo/dirdat/rt09
 -rwxrwxrwx 1 vagrant vagrant 0 Feb 20 16:58 /media/swrepo/dirdat/rt10
 [vagrant@racnode-dc1-1 ~]$
 [vagrant@racnode-dc1-1 ~]$
 [vagrant@racnode-dc1-1 ~]$ export TRAIL_PREFIX=jk*
 [vagrant@racnode-dc1-1 ~]$ ls -l $NEW_DIRDAT
 total 0
 -rwxrwxrwx 1 vagrant vagrant 0 Feb 20 16:58 rt06
 -rwxrwxrwx 1 vagrant vagrant 0 Feb 20 16:58 rt07
 -rwxrwxrwx 1 vagrant vagrant 0 Feb 20 16:58 rt08
 -rwxrwxrwx 1 vagrant vagrant 0 Feb 20 16:58 rt09
 -rwxrwxrwx 1 vagrant vagrant 0 Feb 20 16:58 rt10
 [vagrant@racnode-dc1-1 ~]$ ls $OLD_DIRDAT/$TRAIL_PREFIX | head -5
 /media/patch/dirdat/jk45454
 /media/patch/dirdat/jk45455
 /media/patch/dirdat/jk45456
 /media/patch/dirdat/jk45457
 /media/patch/dirdat/jk45458
 [vagrant@racnode-dc1-1 ~]$ ls $OLD_DIRDAT/$TRAIL_PREFIX | tail -5
 /media/patch/dirdat/jk45456
 /media/patch/dirdat/jk45457
 /media/patch/dirdat/jk45458
 /media/patch/dirdat/jk45459
 /media/patch/dirdat/jk45460
 [vagrant@racnode-dc1-1 ~]$ cp -fv $(ls $OLD_DIRDAT/$TRAIL_PREFIX | tail -5) $NEW_DIRDAT
 ‘/media/patch/dirdat/jk45456’ -> ‘/media/swrepo/dirdat/jk45456’
 ‘/media/patch/dirdat/jk45457’ -> ‘/media/swrepo/dirdat/jk45457’
 ‘/media/patch/dirdat/jk45458’ -> ‘/media/swrepo/dirdat/jk45458’
 ‘/media/patch/dirdat/jk45459’ -> ‘/media/swrepo/dirdat/jk45459’
 ‘/media/patch/dirdat/jk45460’ -> ‘/media/swrepo/dirdat/jk45460’
 [vagrant@racnode-dc1-1 ~]$ ls -l $NEW_DIRDAT/*
 -rwxrwxrwx 1 vagrant vagrant 0 Feb 20 16:59 /media/swrepo/dirdat/jk45456
 -rwxrwxrwx 1 vagrant vagrant 0 Feb 20 16:59 /media/swrepo/dirdat/jk45457
 -rwxrwxrwx 1 vagrant vagrant 0 Feb 20 16:59 /media/swrepo/dirdat/jk45458
 -rwxrwxrwx 1 vagrant vagrant 0 Feb 20 16:59 /media/swrepo/dirdat/jk45459
 -rwxrwxrwx 1 vagrant vagrant 0 Feb 20 16:59 /media/swrepo/dirdat/jk45460
 -rwxrwxrwx 1 vagrant vagrant 0 Feb 20 16:58 /media/swrepo/dirdat/rt06
 -rwxrwxrwx 1 vagrant vagrant 0 Feb 20 16:58 /media/swrepo/dirdat/rt07
 -rwxrwxrwx 1 vagrant vagrant 0 Feb 20 16:58 /media/swrepo/dirdat/rt08
 -rwxrwxrwx 1 vagrant vagrant 0 Feb 20 16:58 /media/swrepo/dirdat/rt09
 -rwxrwxrwx 1 vagrant vagrant 0 Feb 20 16:58 /media/swrepo/dirdat/rt10
 [vagrant@racnode-dc1-1 ~]$
 
In conclusion, automation does not have to be complex. “Make things as simple as possible, but no simpler.” Albert Einstein

No Comments Yet

Let us know what you think

Subscribe by email