Shell Scripting

Saturday, February 7, 2015

How to see the contents of cwallet.sso using Orapki

When using a file-based credential store with Oracle, credentials ultimately get stored in a wallet file (cwallet.sso).

Very little if any info exists on how to dump the contents of the wallet.  At best, most people leverage the trusty orapki command to get an overview of what’s inside as far as the maps and keys, but actual password information is never divulged.


Below is the command we will use to display the contents of cwallet.sso



./orapki wallet display -wallet Path/cwallet.sso

Sunday, February 1, 2015

Useful Unix commands

CD:
cd ~ : To go to home directory.

cd - : Switches from current path to previous path.

$head :   It displays the first n lines from the file.
  Syn: $head –n filename
  Ex: $head -10 userlist.txt

$comm: It displays common lines b/w 2 files.
  Syn:$comm file1 file2

xmllint: To read XML file in unix
xmllint --format AbInitioWebServicesConfig.xml

Zip files:
zcat: it is used for to open zip file in readable format.
   $zcat sample.gz

gzgrep: view the content of GZ file by using below command
gzgrep -i "merchRepNum:[0-9]" McsApplication.txt*

Grep:
1)grep -i Running filename  ---ignore casesenstive
       2----
       5----
     
2)grep –c Running filename –-- counts no of lines
               3

3)grep –n Running filename ---- prints along with line no’s.
              2:--------
              5:-------
           
4)grep -l Running *  -- list only files
       file1
       file2
       file3
     
5)grep -v "Server started" filename –-- It will print the lines which are not matches

fgrep: [faster grep]
It is used for to search multiple strings. But it doesn’t allow to search regular expressions.

Ex: fgrep "pavan
      >unix
      >linux " filename
It searches either pavan or unix or linux

egrep:[ Extended grep]
It is a combination of grep and fgrep
Ex: egrep "pavan
      >unix
      >linux " filename
egrep "^d" filename

Shell Scripting: Part 1

1. UNIX command should be in back cotes (`) in echo statement, otherwise it treats as a text.

bash-3.2$ echo "todays date is :`date`"
o/p-todays date is :Sun Feb  1 09:36:33 EST 2015
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

2. "Constant": It is a fixed value it doesn’t change during execution of the program.

$readonly a
When the variable is made readonly the shell doesn’t allow you to change their values.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

3. Shell script for doing simple arithmetic operations

Note1: Expr is a command to evaluating arithmatic expressions.But expr is capable of carrying out only integer arthematic.

Note2: *_ ? [] ---wild chard characters we will use “\”. And there be no space b/w this wild card character "\" and arithmetic operator as per below product expr ex: "expr $a \* $b"

Note3: Also there should be no space b/w variable and expression. There should be space b/w variables used in arithmetic operations. for ex: $a / $b

echo "enter 2 numbers"
read a b
c=`expr $a + $b`
echo "addition is $c"
e=`expr $a \* $b`
echo "product is $e"
f=`expr $a / $b `
echo "division is $f"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

4. Relational operators: -gt (>),- lt(<) ,- ge (>=),-le (<=),-eq(=),-ne(!=)

5.  Below are some variables which will help in scripting

$$ is the PID of the current process.

$? is the return code of the last executed command.

$# is the number of arguments in $*

$* is the list of arguments passed to the current process

Cut command R and D

Below is the content from a file called Userlist
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
apache:x:48:48:Apache:/var/www:/sbin/nologin
dovecot:x:97:97:dovecot:/usr/libexec/dovecot:/sbin/nologin
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
avahi-autoipd:x:100:156:avahi-autoipd:/var/lib/avahi-autoipd:/sbin/nologin
daniel:x:86:86:Sabayon user:/home/sabayon:/sbin/nologin
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1. Select Column of Characters using Range
----------------------------------------
Range of characters can also be extracted from a file by specifying start and end position delimited with -. The following example extracts first 3 characters of each line from a file called userlist

bash-3.2$ cut -c1-3 userlist
apa
dov
nfs
ava
dan
------------------------------------------
Note: If you like to extract a some part of the output, you can combine option -f and -d. The option -f specifies which field you want to display, and the option -d specifies what is the field delimiter you are going to use to display the desired output

2. Select Column of Characters using either Start or End Position

Either start position or end position can be passed to cut command with -c option.
The following specifies only the start position before the ‘-’. This example extracts from 2nd character to end of each line from userlist file.

bash-3.2$ cut -c2- userlist
pache:x:48:48:Apache:/var/www:/sbin/nologin
ovecot:x:97:97:dovecot:/usr/libexec/dovecot:/sbin/nologin
fsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
vahi-autoipd:x:100:156:avahi-autoipd:/var/lib/avahi-autoipd:/sbin/nologin
aniel:x:86:86:Sabayon user:/home/sabayon:/sbin/nologin
-----------------------------------------------
3. Select a multiple Fields from a File

You can also extract more than one fields from a file or stdout. Below example displays username and home directory of users who has the login shell as “/sbin/nologin”.

bash-3.2$ grep "/sbin/nologin" userlist | cut -d':' -f1,6
apache:/var/www
dovecot:/usr/libexec/dovecot
nfsnobody:/var/lib/nfs
avahi-autoipd:/var/lib/avahi-autoipd
daniel:/home/sabayon
--------------------------------------------------