Category: Unix-Linux Administration

Nov 12 2009

Unix Script: IMPSHOW2SQL – Extracting SQL from an EXPORT file

This is a short script that allows you to extract the SQL from an export file. It is intended for use on UNIX machines. Instructions are in the header of the script.
When entering the script ensure: A> The first line in the file should be a single colon (:)
Please note this is a proto-type script so there may be some statements in the resultant file that need manual editting.
:
$ imp user/password file=exportfile show=Y log=/tmp/showfile

$ ./impshow2sql /tmp/showfile > /tmp/imp.sql

Note: This script may split lines incorrectly for some statements so it is best to check the output.

# CONSTRAINT “” problem:
# You can use this script to help get the SQL from an export then correct it if it includes bad SQL such as CONSTRAINT “”.
# Eg:
# Use the steps above to get a SQL script and then
# $ sed -e ‘s/CONSTRAINT “”//’ infile > outfile
Now precreate all the objects and import the export file.
#
# Extracting Specific Statements only:
# It is fairly easy to change the script to extract certain statements only. For statements you do NOT want to extract change N=1 to N=0 Eg: To extract CREATE TRIGGER statements only:
a) Change all lines to set N=0.
Eg: / \”CREATE / { N=0; }
This stops CREATE statements being output.
b) Add a line (After the general CREATE line above):
/ \”CREATE TRIGGER/ { N=1; }
This flags that we SHOULD output CREATE TRIGGER statements.
c) Run the script as described to get CREATE TRIGGER statements.
awk ‘ BEGIN { prev=”;” }
/ \”CREATE / { N=1; }
/ \”ALTER / { N=1; }
/ \”ANALYZE / { N=1; }
/ \”GRANT / { N=1; }
/ \”COMMENT / { N=1; }
/ \”AUDIT / { N=1; }
N==1 { printf “\n/\n\n”; N++ }
/\”$/ { prev=”"
if (N==0) next;
s=index( $0, “\”" );
if ( s!=0 ) {
printf “%s”,substr( $0,s+1,length( substr($0,s+1))-1 )
prev=substr($0,length($0)-1,1 );
}
if (length($0)<78) printf( "\n" );
}' $*

Oct 15 2009

How to Kill an Unix Process

- kill

– kill soft kill

– kill -9 hard kill

– kill -23 stop a process

– kill -25 unstop

Oct 15 2009

unix active process viewing

- active process viewing

– prstat -a: alternative to top

– top: j for next screen, k for previous screen, q to quit

– ps -e -o time,user,pid,pcpu,vsz,rss,args | grep SBORCL | sort -nr -k 4

– /proc (procfs): process file system

– stores images of active processes by process id

- /usr/proc/bin: contains process tools

Oct 11 2009

SUN CLUSTER

- cluster status

/usr/cluster/bin/scstat -g

- for cluster info
pkginfo -l SUNWscr

- LV: /usr/sbin/vxedit -g opsdg -v set user=oracle group=dba control01.ctl

- VG: /usr/sbin/vxassist -g opsdg -U gen make control01.ctl 51m c0t1d0

- VG with striping:

/usr/sbin/vxassist -g opsdg -U gen make systemA.dbf 2001m layout=stripe,nolog stripeunit=128k c0t1d4 c0t1d5 c0t1d6 c0t1d7

- Sun Cluster System Cluster Control Pannel UI

– ccp run from cluster console server

Oct 11 2009

cluster commands

– cmruncl

– cmviewcl -v

– cmviewcl -p

– cmgetconf -c get cluster config file

– cmgetconf -p get package config file

- cluster formation:

1. determine nodes

2. put IPs for nodes and cluster packages in /etc/hosts

3. cable nodes with unique SCSI IDs

4. configure LVM on all nodes

5. swinstall on all nodes

6. make all nodes trusted systems (/etc/cmcuster/cmcodelist)

7. build/mdify/run cofig file:

– cmquerycl -C -n -n

– vi

– cmcheckconf

– cmapplyconf

8. cmruncl

- package formation:

1. get IP for package

2. mkdir for package on all nodes (/etc/cmcluster/ )

3. ftp application code to directory

4. cmmakepkg -p .config and modify

5. cmmakepkg -s .ctl and modify then ftp to all nodes

6. cmcheckconf -p / .config

7. cmapplyconf -p / .config

8. cmrunpkg -v

9. cmmodpkg -e to enable package switching

10. cmviewcl -v

- node commands:

– cmrunnode

– cmhaltnode

Oct 11 2009

HP-UX LVM – LOGICAL VOLUME MANAGER

- logs:

– /etc/cmcluster/ / .clt.log

– /var/adm/syslog/syslog.log

- volume group work should be performed on the primary node

- dd: copy raw LV to file system file: dd if= of= bs=1024

- lvmtab (/etc/lvmtab): read using strings /etc/lvmtab

- VG Export/Import steps: perform all as root

1. BOTH: stop all instances

2. BOTH: vgchange -a n for all effected VGs on all nodes

3. PRIMARY: vgexport -s -p -m

4. SECONDARY if VG already exists, remove it using: vgexport

5. SECONDARY: mkdir

6. SECONDARY: mknod /group c 64 minor num same as primary

7. SECONDARY: vgimport -v -s -m

8. SECONDARY: chown oracle /*

9. SECONDARY: Make directory unwritable by oracle: chmod 755 /.

10. BOTH (primary 1st): vgchange -c y -S y

11. BOTH (primary 1st): vgchange -a s

12. BOTH: vgdisplay -v ensure L_Vs are visible

13. BOTH: start all instances

Oct 11 2009

LVM Commands: VG and LV

– vgcreate – create volume group:

1. ioscan -funC disk to get disk info

2. pvcreate -f /dev/rdsk/ on all nodes

3. mkdir /dev/ on all nodes

4. mknod /dev//group c 64 0x0000 on all nodes

5. vgcreate /dev/vg_name> /dev/dsk/

– vgdisplay:

– vgdisplay -v /dev/vgptles1

– disk usage for volume group displayed under — Physical volumes —

multiply Total PE and Free PE by 4 to get Meg (ex. 1023 = 4092M or 4G)

– vgchange:

– deactivate: vgchange -a n

– exclusive mode: vgchange -a e

– place in HA cluster and sharable: vgchange -c y -S y

– shared mode: vgchange -a s

– vgexport:

– remove an existing VG: vgexport

– create map file: vgexport -s -p -m
(in HA cluster)

– vgimport:

– import map file: vgimport -v -s -m
(in HA cluster)

– vgscan:

– recovery for lost VG and LV’s

– review actions but DO NOT update /etc/lvmtab: vgscan -p -v

– lvcreate:

1. lvcreate -L xx -n (xx = Size in Meg)

ex. lvcreate -L 55 -n ptles1_system_1 /dev/vgptles1

note: size in Meg is rounded up to nearest multiple of 4

2. newfs /dev/vg../r

3. mount /dev/vg../ /

4. perform VG export/import

– lvremove:

1. BOTH: vgchange -a n

2. PRIMARY: vgchange -a e

3. PRIMARY: lvremove -f /dev/vgptles1/erl_evpm_d_999

4. perform VG export/import

– lvextend: lvextend -L where is the NEW size

Oct 11 2009

UUENCODE – Email attachment

UUENCODE:

- to email attachments

- example

file_str=/export/home/oracle/dba/log/temp/.txt
new_str=/export/home/oracle/dba/log/temp/.xls
uuencode ${file_str} ${new_str} | mailx -s “

Oct 11 2009

FIND Command to remove files in a Directory

FIND Command to remove files in a Directory

- remove all files in a directory:

find /var/spool/mqueue ?type f ?exec rm {} \;

Oct 11 2009

Split the large file

Split the large file

- to split a large file. creates numerous output files with a suffix added

split -l 10000

ex. split -l 10000 alertTEST.log alertTEST_

Alibi3col theme by Themocracy