Linux | Send mail using internal mail command

November 16, 2016

Hi guys

We are on VEEM+VMWare infrastructure from a while, yet I am paranoid to maintain copies of the backups on different media once after going through couple of nightmares. We take weekly cold backup for our ERP Production server, move the tar files to a standby Linux server, and move those backups once again to an external HDD.

So basically I have a full VM backed up, the same VM holds a weekly cold backup, standby Linux server holding a copy of the cold backup files & to finish it, again copied to an external HDD. The funniest part is, we are moving the entire VMs to a TANDBERG Quick Station as well!

Though everything works fine till date, the last part of the deal needs to intimate me about successful completion of copying the tar files to the external media, ie, HDD that is formatted using NTFS, so that I can use it on both Linux and Windows environments

Be warned: The below bash script only works in an environment that has an internal SMTP server (or I don’t know how to relay the messages through an external SMTP relay and to disappoint you further, I don’t care about relaying through external SMTP). In addition, you must be on Linux 6 and above to use the internal mail command as demonstrated below. Linux 5 doesn’t support many switches provided with the example.

Further, below example demonstrates the basic level of error capturing with “bash” scripts as well

#!/bin/bash
/bin/cp -rf /u02/backup/PROD_DAILY_BACKUP*.* /media/Elements/ 2> /dev/null

if [ $? -eq 0 ]
then
echo "The files were successfully copied to external hard disk" | mailx -v -s "ERP Tar Files Moved to External HDD | Success" -S smtp=smtp://server.domain.com -S from="ERP Alerts <someone@example.com>" someoneelse@example.com,someone2@example.com
else
echo "Files were not copied to external HDD" | mailx -v -s "ERP Tar Files to External HDD | Failed" -S smtp=smtp://server.domain.com -S from="ERP Alerts <someone@example.com>" someoneelse@example.com,someone2@example.com
fi

Try it and let e know whether it worked for you :)

regards,

rajesh


Oracle E-Business Suite R12.0 | Automating clone process

February 16, 2016

Hi guys

A clone is the exact replica of a production instance, against what you do all tests, custom development and patch deployments to insure that your attempts are NOT going to break the PRODUCTION instance once such are moved over to.

How often consultants & users may request for a fresh clone (with latest data) depends upon many factors. During the implementation time, a DBA could be bombarded with requests for cloning almost once in couple of days. Although I am “not a dba”, I have been doing cloning to learn & understand the technology from last couple of years time & trust me, it is NOT at all fun. Especially once after you are familiar with the tasks.

Throughout last few months I was trying to “fully automate” the entire cloning process and made significant advancements with the process. I will share my experiences with you today

Scenario:

We have a cron job initiated by “root” user, starting by 2:30 PM every Friday, that shuts down the application and database after running pre-cloning. The same script makes tar balls for both the database and application nodes in separate files and then copies the tar balls to our TEST instance server.

Logically once the tar balls are copied to TARGET (TEST) server, following activities are expected from the DBA

  1. Stop the application & database instances those are online in the TEST server
  2. Extract the tar balls copied from PRODUCTION instance to relevant folders
  3. Clone database tier, followed by application tier
  4. Tune the database with TEST server specific SGA/job queue processes etc parameters

What if I am too lazy & a scripting junkey who wants to automate the entire activities using shell scripts? The following demonstrates such an attempt

Why not a cron job? ;)

The first step will be, creating auto response files for both database and application nodes. I have already detailed a how to here

ebsclone.sh | This shell script calls a number of other shell scripts to facilitate the entire cloning process

Please note, my Oracle database user is “oraprod” and application manager is “applprod”. If you are planning to copy the below script(s), make sure you change the physical paths, user details according to your specific environment.

Both the database and application manager user accounts are enhanced with .bash_profile values. Hence most of my scripts will not populate the environment variables prior executing other scripts.

I am using “expect”, that YOU must install, if not already installed in order to automate the cloning process. If you are using Oracle linux, you can install expect by issuing the following command:

yum install expect -y
#!/bin/bash
# As a precaution to make sure the port pool is available during automated
# Cloning, we will kill all orphaned processes those were not closed during
# DB, APPS stop

# Kill all processes for both oraprod &amp; applprod users
echo &quot;Killing all processes for Oracle user&quot;
pkill -u oraprod
echo &quot;Killing all processes for Application user&quot;
pkill -u applprod
echo &quot;All processes for both Oracle and Application users were killed&quot;

sleep 30

echo &quot;$(date)&quot;

#Remove the existing physical folder for database files
cd /u01
find oraprod -delete
echo &quot;finished deleting Oracle top at $(date)&quot;
#Extract files for database top from the cold backup archive
echo &quot;Extract database backup file at $(date)&quot;
time tar -zxf /u02/backup/PROD_DAILY_BACKUP_db.tar.gz
echo &quot;Finished extracting database backup file at $(date)&quot;

#Remove the existing physical folder for application files

cd /u03
find applprod -delete
echo &quot;finished deleting Application top at $(date)&quot;

#Extract files for application top from the cold backup archive
echo &quot;Extract application backup file at $(date)&quot;
time tar -zxf /u02/backup/PROD_DAILY_BACKUP_apps.tar.gz u06/applprod/PROD/apps
echo &quot;Finished extracting application backup file at $(date)&quot;

#Move the files around based on your configuration files (db.xml &amp; apps.xml)

mv /u01/u05/oraprod /u01
mv /u03/u06/applprod /u03

#Change the ownership of the folders, so that corresponding users could read &amp; execute files

chown -R oraprod:oinstall /u01/oraprod
chown -R applprod:oinstall /u03/applprod

########################################
#Start the cloning
########################################

echo &quot;Database cloning phase starts now, $(date)&quot;

#su - oraprod -c &quot;perl /u01/oraprod/PROD/db/tech_st/10.2.0/appsutil/clone/bin/adcfgclone.pl dbTier /u01/clonescripts/db.xml&quot;

/root/scripts/dbclone.sh

sleep 30

echo &quot;Application cloning phase starts now, $(date)&quot;

# su - applprod -c &quot;perl /u03/applprod/PROD/apps/apps_st/comn/clone/bin/adcfgclone.pl appsTier /u01/clonescripts/apps.xml&quot;

/root/scripts/appsclone.sh

echo &quot;EBS Cloning completed, $(date)&quot;
######################################
#Optional steps for changing database SGA parameters,
#startup configuration files to spfile etc
######################################
echo &quot;Changing database parameters, $(date)&quot;

/root/scripts/dbfix.sh

echo &quot;Done! Application online with changed database parameters, $(date)&quot;

Now I will copy the code for each script called within the ebsclone.sh script
dbclone.sh | script enabled with expect which will not ask for the apps password

#!/usr/bin/expect -f
set force_conservative 0  ;

# set to 1 to force conservative mode even if
# script wasn't run conservatively originally

if {$force_conservative} {
        set send_slow {1 .1}
        proc send {ignore arg} {
                sleep .1
                exp_send -s -- $arg
        }
}

set timeout -1

spawn su - oraprod -c &quot;perl /u01/oraprod/PROD/db/tech_st/10.2.0/appsutil/clone/bin/adcfgclone.pl dbTier /u01/clonescripts/db.xml&quot;

match_max 100000

expect -exact &quot;\r
Enter the APPS password : &quot;
send -- &quot;apps\r&quot;

expect eof

appsclone.sh | script enabled with expect which will not ask for the apps password

#!/usr/bin/expect -f
set force_conservative 0  ;

# set to 1 to force conservative mode even if
# script wasn't run conservatively originally

if {$force_conservative} {
        set send_slow {1 .1}
        proc send {ignore arg} {
                sleep .1
                exp_send -s -- $arg
        }
}

set timeout -1

spawn su - applprod -c &quot;perl /u03/applprod/PROD/apps/apps_st/comn/clone/bin/adcfgclone.pl appsTier /u01/clonescripts/apps.xml&quot;

match_max 100000

expect -exact &quot;\r
Enter the APPS password : &quot;
send -- &quot;apps\r&quot;

expect eof

dbfix.sh | Changing database parameters like SGA, job queue processes etc

#!/bin/bash
su - applprod -c &quot;/u03/applprod/PROD/inst/apps/PRODBAK_erp-prodbak/admin/scripts/adstpall.sh apps/apps&quot;
su - oraprod -c /root/scripts/dbalter.sh
su - applprod -c &quot;/u03/applprod/PROD/inst/apps/PRODBAK_erp-prodbak/admin/scripts/adstrtal.sh apps/apps&quot;

Finally dbalter.sh | All database alter commands are included within this file

#!/bin/bash
export ORACLE_HOME=/u01/oraprod/PROD/db/tech_st/10.2.0
export ORACLE_SID=PRODBAK

#http://www.cyberciti.biz/faq/unix-linux-test-existence-of-file-in-bash/
#Check whether spfile already exist
file=&quot;/u01/oraprod/PROD/db/tech_st/10.2.0/dbs/spfilePRODBAK.ora&quot;
if [ -f &quot;$file&quot; ]
then
	echo &quot;$file found. Aborting database configuration now&quot;
exit;
else
	echo &quot;$file not found.&quot;
fi

sqlplus &quot;/ as sysdba&quot; &lt;&lt;EOF
create spfile from pfile;
shutdown immediate;
startup;
alter system set sga_max_size=8G scope=spfile;
alter system set sga_target=8G scope=spfile;
alter system set job_queue_processes=10 scope=both;
shutdown immediate;
! cp /u01/oraprod/PROD/db/tech_st/10.2.0/dbs/initPRODBAK.ora /u01/oraprod/PROD/db/tech_st/10.2.0/dbs/initPRODBAK.ora.original
! &gt;/u01/oraprod/PROD/db/tech_st/10.2.0/dbs/initPRODBAK.ora
! echo &quot;spfile=/u01/oraprod/PROD/db/tech_st/10.2.0/dbs/spfilePRODBAK.ora&quot; &gt;&gt;/u01/oraprod/PROD/db/tech_st/10.2.0/dbs/initPRODBAK.ora
startup;
exit;
EOF

The above five scripts should do what they are meant to. Just copy the files to same folder
Change the execute mode of ebsclone.sh

chmod +x ebsclone.sh

and execute the ebsclone.sh as “root” (attempts made with other users will fail the cloning)

#./ebsclone.sh

Prior attempting, please make sure all the above scripts are modified with absolute paths, referring to your existing partitions & other

Download the scripts here

References:

Sample expect script

https://community.oracle.com/thread/2558592?start=0&tstart=0

Linux: Find whether a file already exist

http://www.cyberciti.biz/faq/unix-linux-test-existence-of-file-in-bash/

Happy cloning!


Linux “service xyz does not support chkconfig”

September 29, 2013

 

Majority of the scripts, which you want to startup certain services during the boot process itself are usually placed (CentOS, RHEL, OUL(Oracle Unbreakable Linux)) in /etc/init.d folder

We had a requirement to disable the automatic startup of Oracle database, which was a part of Oracle Vision Instance 12.1.3

The vision database node server on Oracle linux, starts up the database services during the boot process itself, thus delaying the booting process.

After a long scrutiny (as I am not very familiar with Linux) I found that during the boot up, one particular service “ebizdb” was being executed and I found a script with automatic execution within “/etc/init.d” folder

Recently I have learned that I could change a .sh script using “chmod” command to executable so that I could call it without using “./” and the syntax was

chmod +x myscript.sh

Just keeping my fingers crossed (make a note of my acceptance that I am not a linux geek) I tried the following

chmod –x ebizdb

and bingo!

Prior that I tried

chconfig ebizdb off

and kept on receiving error message stating “service ebizdb does not support chkconfig”

The job was done by just the script’s behavior from executable to non-executable.

Hope this helps few out there, who are Linux noobies like me!

 

regards,

admin