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


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.

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

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


[[email protected] ~]#  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.

[[email protected] audit]#  find . -name "*trc" -print | xargs rm -rf


[[email protected] audit]#  find . -name "*trm" -print | xargs rm -rf

[[email protected] 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




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 server for the first time.

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



Linux disk format

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

[[email protected] ~]# 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)
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.
[[email protected] ~]#



You can format partitioned disk  ( ext4 type ) like below

[[email protected] ~]# 
[[email protected] ~]# 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.
[[email protected] ~]#


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

[[email protected] /]# mkdir /oracle
[[email protected] /]# mount -t ext4 /dev/sdb1 /oracle
[[email protected] /]# 
[[email protected] /]# 
[[email protected] /]# df -h
Filesystem            Size  Used Avail Use% Mounted on
                       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
[[email protected] /]#


Add route &  default gateway


You can add default gateway to the linux like below.

route add default gw


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

route delete default gw eth1


You can add routing and gateway settings like below.

route add -net gw

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

[[email protected] ~]#
[[email protected] network-scripts]# cat route-eth1 via dev eth1 via dev eth0


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

[[email protected] network-scripts]# service network restart


then Routing will be like below.

[[email protected] network-scripts]# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default UG 0 0 0 eth0
link-local * U 0 0 0 ibbond0 * U 0 0 0 eth0 * U 0 0 0 ibbond0 * U 0 0 0 veth1 UG 0 0 0 veth1 UG 0 0 0 eth1 * 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


 1,338 views last month,  1 views today

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.


  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

Do NOT follow this link or you will be banned from the site!