Useful Linux Scripts & Shell Scripts for Oracle DBA | Oracle DBA Scripts All in One -7

Hi,

I will share all Oracle DBA Scripts ( Oracle RAC, Dataguard, Performance Tuning, Monitoring and etc.. ) in this tutorial series.

 

Useful Linux Scripts

Oracle DBA ( Database Administrator ) needs useful scripts to monitor, analyze and check Oracle database for routine database operations and monitoring.

 

Oracle DBA Scripts All in One post will be updated with new Oracle DBA Scripts.

 

 

Before Oracle DBA Scripts, If you don’t know Oracle database and want to learn, click following link to start learning Oracle database with this tutorial.

 

Oracle Tutorial | Oracle Database Tutorials for Beginners ( Junior Oracle DBA )

 

 

 

Oracle DBA Scripts All in One

 

Useful Linux Scripts for Oracle DBA

 

You can use following query to learn the biggest size directory and files

du -k * | sort -nr | cut -f2 | xargs -d '\n' du -sh |more




You need killing all processes of any user , then you can use following code.

[root@MehmetSalih ~]#  kill -9 `ps -ef|grep oracle | awk '{print $2}'`


For example, You have stopped Oracle EBS with adstpall.sh, but you have still EBS Process belong to applmgr, You can kill all processes of applmgr user like following.

 

[root@MehmetSalih ~]#  kill -9 `ps -ef|grep applmgr | awk '{print $2}'`


You can change *aud extension to the *trc or *trm. You can delete all trc extension files like following if their argument list too long.

[root@MehmetSalih audit]#  find . -name "*trc" -print | xargs rm -rf

 

[root@MehmetSalih audit]#  find . -name "*trm" -print | xargs rm -rf

[root@MehmetSalih audit]#  find . -name "*.log" -print | xargs rm -rf

 

–For IBM AIX, Delete all files which extensions are like .trc Under /oracle directory

find /oracle -name "*.trc" -type f -exec rm -f {} \;

 

— For Linux, Delete all files which extensions are like .aud Under /u01 directory

find /u01 -name "*aud" -print | xargs rm -rf

 

You may want to delete files older than 3 days, you can use following query.

find / -name "*.log" -mtime +3 -print | xargs rm -rf

 

You can change extension name and directory name to delete according to your need

 

Shell Scripts for Oracle DBA

If your application and security rules don’t need any firewall then you can disable it with below script.

service iptables stop
chkconfig iptables off

service ip6tables stop
chkconfig ip6tables off

 

 

You can disable firewall in Redhat with below script.

systemctl stop firewalld
systemctl disable firewalld


You can install VNC Server on Oracle Linux with below yum packages.

yum install tigervnc-server

yum install xterm
yum install twm

yum install xhost

 

 

Rsync 

You can transfer and syncronized backup files to the Remote server for disaster purpose using rsync.

For example, execute following command to transfer all contents of /u01/backup to the 192.168.63.63 server for the first time.

rsync -av --delete --inplace /u01/backup/* 192.168.63.63:/u01/backup/ --rsync-path=/usr/bin/rsync > /tmp/rsync.log

 

 

Linux disk format

You can partition /dev/sdb disk with fdisk tool like below.

[root@deveci ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x786292ec.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').

Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1305, default 1): 
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-1305, default 1305): 
Using default value 1305

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@deveci ~]#

 

 

You can format partitioned disk  ( ext4 type ) like below

[root@deveci-1 ~]# 
[root@deveci-1 ~]# mkfs -t ext4 /dev/sdb1
mke2fs 1.41.12 (17-May-2010)
/dev/sdc is entire device, not just one partition!
Proceed anyway? (y,n) y
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
65536 inodes, 262144 blocks
13107 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=268435456
8 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
32768, 98304, 163840, 229376

Writing inode tables: done 
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 29 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@deveci-1 ~]#

 

You can create related directory and mount this volume group with this directory.

[root@deveci-1 /]# mkdir /oracle
[root@deveci-1 /]# mount -t ext4 /dev/sdb1 /oracle
[root@deveci-1 /]# 
[root@deveci-1 /]# 
[root@deveci-1 /]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_ora12c-lv_root
                       46G   24G   19G  56% /
tmpfs                 1.7G  779M  940M  46% /dev/shm
/dev/sda1             485M   76M  384M  17% /boot
/dev/sdc             1008M   34M  924M   4% /oracle
[root@deveci-1 /]#

 

Add route &  default gateway

 

You can add default gateway to the linux like below.

route add default gw 192.168.163.1

 

If you want to delete default gateway you can execute like following script.

route delete default gw 192.168.163.1 eth1

 

You can add routing and gateway settings like below.

route add -net 192.168.63.0/24 gw 192.168.163.1

Or if you want to do permanent routing, you can create route file like below.

[root@deveci02 ~]#
[root@deveci01 network-scripts]# cat route-eth1
192.168.63.0/24 via 192.168.163.1 dev eth1
192.168.161.0/24 via 192.168.161.1 dev eth0

 

If you create routing file like above then you can restart network service like below.

[root@deveci01 network-scripts]# service network restart

 

then Routing will be like below.

[root@deveci01 network-scripts]# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default 192.168.161.1 0.0.0.0 UG 0 0 0 eth0
link-local * 255.255.0.0 U 0 0 0 ibbond0
192.168.161.0 * 255.255.255.0 U 0 0 0 eth0
192.168.16.0 * 255.255.255.0 U 0 0 0 ibbond0
192.168.18.0 * 255.255.255.0 U 0 0 0 veth1
192.168.19.0 192.168.18.1 255.255.255.0 UG 0 0 0 veth1
192.168.63.0 192.168.163.1 255.255.255.0 UG 0 0 0 eth1
192.168.163.0 * 255.255.255.0 U 0 0 0 eth1

 

 

 

Read the following Tutorial series to learn GNU/Linux Bash Commands Tutorial for Beginners

GNU/Linux Bash Commands Tutorial for Beginners -6 Network Commands

 

You can access the third Oracle DBA scripts related to Blocking Sessions and Lock Kill Scripts with following link.

Oracle Database Check Scripts and Database Inventory Scripts | Oracle DBA Scripts All in One -6

Find Blocking Sessions and Kill Locked Session Scripts & Locked Objects | Oracle DBA Scripts All in One -3

 

 

Do you want to learn Oracle Database Performance Tuning detailed, then read the following articles.

Performance Tuning and SQL Tuning Tutorial in the Oracle Database

 

About Mehmet Salih Deveci

I am Founder of SysDBASoft IT and IT Tutorial and Certified Expert about Oracle & SQL Server database, Goldengate, Exadata Machine, Oracle Database Appliance administrator with 10+years experience.I have OCA, OCP, OCE RAC Expert Certificates I have worked 100+ Banking, Insurance, Finance, Telco and etc. clients as a Consultant, Insource or Outsource.I have done 200+ Operations in this clients such as Exadata Installation & PoC & Migration & Upgrade, Oracle & SQL Server Database Upgrade, Oracle RAC Installation, SQL Server AlwaysOn Installation, Database Migration, Disaster Recovery, Backup Restore, Performance Tuning, Periodic Healthchecks.I have done 2000+ Table replication with Goldengate or SQL Server Replication tool for DWH Databases in many clients.If you need Oracle DBA, SQL Server DBA, APPS DBA,  Exadata, Goldengate, EBS Consultancy and Training you can send my email adress [email protected].-                                                                                                                                                                                                                                                 -Oracle DBA, SQL Server DBA, APPS DBA,  Exadata, Goldengate, EBS ve linux Danışmanlık ve Eğitim için  [email protected] a mail atabilirsiniz.

7 comments

  1. Great work bro..

  2. where is setenv and srvctl kept – I am trying to build a new db on a ew linux server thanks

Leave a Reply

Your email address will not be published. Required fields are marked *