UNIX for DBAs and Oracle APPS DBAs

UNIX CommandsDescription :
UNIX for DBAs
Basic and Advance commands example
Example :

*** Few of the command here are really dangerous , Please be very careful to run these commands**** UNIX Command for Expert users ***
tarCreate tape archives and add or extract files

Note: There is no "untar" linux / unix command.

Backup Oracle applications file system
In this example , I am using tar command to create the zipped archive of Oracle applications file system (Including appltop,common top, ias oracle home, 806 oracle home

So many ways to use it.
This is how you can create tape archives , (tar + gzip saves lot of space)
tar -cvf - 8.0.6 |gzip -c > 8.0.6.tar.gz
tar -cvf - appl |gzip -c > appl.tar.gz
tar -cvf - comn |gzip -c > comn.tar.gz
tar -cvf - iAS |gzip -c > iAS.tar.gz
This is how you can restore the files to normal files from archives.
nohup gunzip -c 806.tar.gz |tar -xvf - >806.out &
nohup gunzip -c comn.tar.gz |tar -xvf - >comn.out & nohup gunzip -c iAS.tar.gz | tar -xvf - > ias.out&
nohup gunzip -c appl.tar.gz | tar -xvf - >appl.out &
If ssh is enables between the servers then you can can use this command
nohup tar -cf - 10.2.0.1| ssh server "(cd /opt/oracle/product/10.2.0.1 && tar -xvf –)" &
tar cf - home|(cd /u01/oracle/product ; tar xvf – )
If remsh is enabled
nohup tar -cf - . | remsh server -l username 'cd /u01/oracle/11.5.10; tar -xf -' &
cd fromdir ; tar cf - . | ( cd todir ; tar xf – )
If rsh is enabled.
/usr/sbin/tar -cEpf - .| /usr/bin/rsh -l username remoteserver "(cd /db1/oracle/appltop && /usr/sbin/tar -xEvpf -)"
/usr/bin/tar -cEpf - . | /usr/bin/rsh -l username remoteserver "(cd /oracle/erpapp && /usr/bin/tar -xEvpf -)"
findCreate  a backup with .bak and search and replace the occurrence of sun with night
find . -exec perl -p -i.bak -e 's/sun/night/g' {} \; 
find . -name '*.bak' -exec rm {} \;

To remove all the files under /usr/oracle which end with .tmp 
find /usr/oracle -name "*.tmp" -print -exec rm -f {} \;
To list all files under /usr/oracle which are modified within a week. 
find /usr/oracle -mtime -7 -print
To compress all files which end with .dmp and are more than 1 MB. 
find . -size +1073741824c -name "*.*" –print

find . -name "*.log" -size +1048576c -mtime +7 -print -exec compress {} \;
kill –9Killing all applmgr process in a single commandps -ef | grep applmgr | grep -v grep | awk '{print $2}' | xargs kill -9 {}\
crontabThis is utility at UNIX which helps you to scheduling the jobs in UNIX###############################################################################
#    crontab guide:
#             *  *  *  *  *
#             |  |  |  |  |
#             |  |  |  |  day of week (0=Sunday  ==>  6=Saturday)
#             |  |  |  month of year  (1=January ==> 12=December)
#             |  |  day of month      (1         ==> 31         )
#             |  hour of day          (0=12AM    ==> 23=11PM    )
#             minute of hour          (0         ==> 59         )
################################################################################
lsls is very basic command in UNIX can be used to list the file

List filename with extension .trc and created on May 22 , Be careful to run this from the correct directory
rm `ls -tlr *.trc | grep "May 22"|awk '{print $9}'`
UNIX CommandsBasic UNIX command

ls : List file and directory
cd : Change Directory
cp : Copy files
mv : To move the file
rm : to remove the files
pwd : to find out present working directory
cat: The cat utility reads each file in sequence and writes it on the standard output.
cut: The cut utility to cut  out  columns  from  a  table  or fields  from  each line of a file
head: The head utility copies the first number of  lines  of  each  filename  to  the  standard output.
tail: The tail utility copies the named file to the standard  output  beginning  at  a designated place.
echo: The echo utility writes its arguments, separated  by  BLANKs and  terminated  by  a  NEWLINE, to the standard output. 
exit: exit will cause the calling shell or shell  script  to  exit with  the  exit  status  specified by n.
break- shell built-in function to escape from  within  a controlling while, for, foreach, or until loop
wc: The wc utility  reads  one  or  more  input  files  and,  by default,  writes the number of newline characters, words and bytes contained in each input file to the standard output.
expr: The expr utility evaluates the  expression  and  writes  the result  to  standard  output.
Unix commands continued
grep: The grep utility searches  text  files  for  a  pattern  and prints  all lines that contain that pattern.
read: The read utility will  read  a  single  line  from  standard input.
sort: The sort command sorts lines of all the named files together and writes the result on the standard output.
test: The test utility evaluates the condition and  indicates  the result  of the evaluation by its exit status. exit status 0=true and 1=false
uniq: The uniq utility will read an input file comparing  adjacent lines,  and write one copy of each input line on the output.
touch: The touch utility sets the access and modification times  of each  file.  The  file  operand  is  created  if it does not already exist. 
date: The date utility writes the date and time to standard output or attempts to set the system date and time. By default, the current date and time will be written.
crontab: The crontab utility manages a user's access with  cron by copying, creating, listing, and removing cron- tab files.



ls –ltr ,ls –la , ls –l
cd /abc/xyz
cp /abc/xyz.txt  /abc/xyz1.txt  , cp –R /abc/* /xyz/
mv abc xyz
rm abc.txt , rm –rf  (Recurcive and force)
pwd

cat abc.txt

cut

head –10 alert.log

tail –50 alert.log , tail –f

echo $ORACLE_HOME

exit

break

ls | wc –l





ps –ef | grep oracle



du -sk *|sort –n


psman ps on UNIX/LINUX for more infoBest of PS command.

1. Load test:
ps -ef|grep applmgr|cut -c1-15,42-79|sort -rn +2 | head -20 | while read LINE
do
print $LINE | awk '{ print $3 }' > abc.txt
echo $CPUTIME
done

***with***
prstat -u applmgr -n 10 -s cpu
prstat -u applmgr -n 10 -s cpu | cut -c52-60
prstat -u applmgr -n 10 -s cpu -P 1,2 1 1 | cut -c54-58 |q
2. We were recently working on a project to which requires me to identify Oracle Home and Listener Home used by the instance. Server was hosting around 8 databases and one ASM instance and was installed with 6 Oracle Homes of same version.
You may think that why these many oracle home, answer is business can't afford a downtime but they can afford extra space. They asked us to create four node RAC which would spread across two different physical location and were connected through ASM and high end optic fibre network.
To restart / reconfigure any of the instances / listener / asm instance we need to target the right oracle home, but since the processes were already started, identifying the oracle home was biggest challenge.
Here is a command to find out oracle home or asm home or listener home used by oracle process.
ps -ef|grep pmon|grep -v grep|awk {'print $2'}|xargs -t -I {} ps eauwww {}
ps -ef|grep tns|grep -v grep|awk {'print $2'}|xargs -t -I {} ps eauwww {}
ps -ef|grep cssd|grep -v grep|awk {'print $2'}|xargs -t -I {} ps eauwww {}

3.  export APP_PASS=password
ps -auxwwee | grep APP_PASS
ps can dump the ENVIRONMENT as well. very handy trick to know, can be useful to see a processes environment

4 ps -ef | grep applmgr | grep -v grep | awk '{print $2}' | xargs kill -9 {}\

5. List listeners with lot of other information including ports
netstat -a | grep -i listen | egrep "com.15[2-9][0-9]|com.16[0-2][0-9]" | cut -d . -f 1,5 | awk '{print substr($1,1,8) "\t" substr($1,10,4)-1521}'


6. ps –ef | grep inherit  : to list all the lsiteners of the server

7 ps –ef | grep FNDLIBR : list all concurrent manager processes
ps –ef | grep CPMGR
ps –ef | grep http
ps –ef | grep oracle
ps –ef | grep applmgr

8. ps -ef  grep "/OAS10g/developemnt" awk -F " " '{print "kill -9 " $2}' > a.sh

9. To find %CPU use by a user : e.gUsage  cpu.sh applmgr
#!/usr/bin/ksh

#name : cpu.sh
for para1 in $*
do
ps -afe -o user -o pcpu -o comm -o args grep "$para1\ " >>aa.lst
if [ "$para1" = "all" ]
then
tcpu=`ps -afe -o user -o pcpu -o comm -o args sort -k2n
awk '{print $2}' grep -v 0.0 sed 's/$/+/g' xargs echo
sed 's/+$//' xargs echo 0 bc`
else
tcpu=`ps -afe -o user -o pcpu -o comm -o args
grep "$para1\ " grep -v grep sort -k2n awk '{print $2}'
grep -v 0.0 sed 's/$/+/g' xargs echo sed 's/+$//'
xargs echo 0 bc`
fi
echo "Total % of Cpu consumed by $para1 = $tcpu"
done

unzipto unzip the fileunzip -t \*.zip >integrity.txt , To check if the .zip is in correct format
findfind filesfind *.out | xargs rm , find . –name *.out | xargs rm
find *.log | xargs rm 

How can I SELECT information into my vi-file?

vi editorHow can I SELECT information into my vi-file?

When using vi to edit SQL*Plus or Pro*C code, sometimes one need to insert a table definition or data values into the file.
You can simply open a new line, put 'desc EMP' (or a SELECT statement) into it and type:
        :.,.!sqlplus -s system/password
... automatically output from your statement arrives in the vi buffer for cutting and pasting. You might even like to consider piping the output through grep, awk, sed or perl.
rsync rsync for appltoprsync -vrl --rsh=ssh --size-only --rsync-path=/opt/local/bin/rsync --exclude-from=rsync_exclude_file $1 $2

Exclude file:
cat rsync_exclude_file
### Log files ###
+ /log/
- **/log/**
- **.log
## out files ###
+ /out/
- **/out/**
- **.out
### req files ###
+ /req/
**.req
### Old files ###
+ /old/
- **.old
+/bak/
- **.bak
- /core

8 comments:

  1. Good one sir but formatting should be taken care i believe

    ReplyDelete
  2. Sure, I will work on this..I am trying to find out the best tool for posting..

    ReplyDelete
  3. This comment has been removed by a blog administrator.

    ReplyDelete
  4. This comment has been removed by a blog administrator.

    ReplyDelete
  5. This comment has been removed by a blog administrator.

    ReplyDelete
  6. This comment has been removed by a blog administrator.

    ReplyDelete
  7. This comment has been removed by a blog administrator.

    ReplyDelete
  8. This comment has been removed by a blog administrator.

    ReplyDelete