Solved

identify the correct shell i need to use for writing scripts for monitoring oracle database

Posted on 2013-05-17
11
461 Views
Last Modified: 2013-05-30
Hello Experts,

i am trying to write some automation scripts for monitoring my oracle database. i have a question on which type of shell i need to use to write scripts.

here the problem is,

oracle user is using different shell on different servers. for example, for few servers they are using ksh , for few servers they are using bash.

is there any way to way to write script in a generalized shell and use for ksh and bash?

another problem is,

i wrote a script for a backup. it is working fine when i ran from command like as "/bin/bash -x rman_backup.sh <parameter>
when i schedule the job via cron, it got failed to identify the parameter values.
here is the error message from /var/mail/oracle log

Your "cron" job on kiran
/u01/app/oracle/backup/rman/rman_backup_modified_new.sh 0 /dev/null 2> /dev/null

produced the following output:

Usage: rman_full_backup.sh: <parameter1>
Usage: rman_full_backup.sh  -- 0 For Full 1 For Incr Backup


please advice
0
Comment
Question by:sk0227
  • 4
  • 3
  • 2
  • +2
11 Comments
 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 39175343
Use the shell script language you are most comfortable with.

You can force the script to use a specific shell regardless of the users 'default' shell with the first line of the script (this is ksh but you can use whatever shell you want):
#!/bin/ksh
0
 

Author Comment

by:sk0227
ID: 39175353
Thank you so much for quick reply. thank for clarification.

why i am getting error when i ran the backup job via cron? whey is running successfully when i ran from command line?
0
 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 39175366
>>it got failed to identify the parameter values.

The script you said you executed from the command line is rman_backup.sh

The cron entry shows rman_backup_modified_new.sh

execute this from the command line:
/u01/app/oracle/backup/rman/rman_backup_modified_new.sh 0
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

Author Comment

by:sk0227
ID: 39175399
slightwv,

my apologies for typo. i have ran the correct script. here is the error message from /var/mail/log

Subject: Output from "cron" command
MIME-Version: 1.0
Content-Type: text/plain
Content-Length: 247

Your "cron" job on kiran
/opt/app/oracle/backup/rman/rman_backup_modified_new.sh 0 /dev/null 2> /dev/null

produced the following output:

Usage: rman_full_backup.sh: <parameter1>
Usage: rman_full_backup.sh  -- 0 For Full 1 For Incr Backup
0
 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 39175405
It looks like there is a syntax error inside the script.

From my post above, execute this from the command line:
/u01/app/oracle/backup/rman/rman_backup_modified_new.sh 0
0
 

Author Comment

by:sk0227
ID: 39175467
Slightwv,

My apologies for confusion on the script location. i have the same script in two different locations.

let me run the same script on different host to avoid confision.

1st time Test:

here is my crontab entry and job is scheduled to execute at 11:00 AM. i am redirecting the output to log.

/opt/app/oracle/backup/rman/log>crontab -l |grep modified
0 11 * * * /opt/app/oracle/backup/rman/rman_backup_modified_new.sh 0 > /opt/app/oracle/backup/rman/log/backup_cron.log

here i got successful backup. verified the backup log.



2nd time:

i have scheduled the same script to redirect the output to null, and commented the first cronjob.

/opt/app/oracle/backup/rman/log>crontab -l |grep modified
#0 11 * * * /opt/app/oracle/backup/rman/rman_backup_modified_new.sh 0 > /opt/app/oracle/backup/rman/log/backup_cron.log --- --------------------commented
10 11 * * * /opt/app/oracle/backup/rman/rman_backup_modified_new.sh 0 /dev/null 2> /dev/null


from /var/mail/oracle log

From oracle@dsp2db1 Fri May 17 11:10:01 2013
Return-Path: <oracle@dsp2db1>
Received: from dsp2db1 (localhost [127.0.0.1])
        by dsp2db1 (8.14.4+Sun/8.14.4) with ESMTP id r4HHA1J4026609
        for <oracle@dsp2db1>; Fri, 17 May 2013 11:10:01 -0600 (MDT)
Received: (from oracle@localhost)
        by dsp2db1 (8.14.4+Sun/8.14.4/Submit) id r4HHA03G026608
        for oracle; Fri, 17 May 2013 11:10:00 -0600 (MDT)
Date: Fri, 17 May 2013 11:10:00 -0600 (MDT)
From: Oracle Account <oracle@dsp2db1>
Message-Id: <201305171710.r4HHA03G026608@dsp2db1>
To: oracle@dsp2db1
Subject: Output from "cron" command

Subject: Output from "cron" command
MIME-Version: 1.0
Content-Type: text/plain
Content-Length: 247

Your "cron" job on dsp2db1
/opt/app/oracle/backup/rman/rman_backup_modified_new.sh 0 /dev/null 2> /dev/null

produced the following output:

Usage: rman_full_backup.sh: <parameter1>


to my understanding, some how the script (/opt/app/oracle/backup/rman/rman_backup_modified_new.sh) is taking "/dev/null" as a parameter.
i am not sure why this is happened.

please advice
0
 
LVL 77

Accepted Solution

by:
slightwv (䄆 Netminder) earned 500 total points
ID: 39175475
Assuming you want all output to go to /dev/null

Change:
/opt/app/oracle/backup/rman/rman_backup_modified_new.sh 0 /dev/null 2> /dev/null

To:
/opt/app/oracle/backup/rman/rman_backup_modified_new.sh 0 > /dev/null 2> &1
0
 
LVL 27

Expert Comment

by:skullnobrains
ID: 39175592
is there any way to way to write script in a generalized shell and use for ksh and bash?

yes but you'll need to stick with very basic sh syntax and basic switches for whatever commands you use. ksh is far from being sh-compatible but does a pretty good job at keeping builtins sh-compatible. bash claims to be sh-compatible but it has never been, most likely never will be and bring a load of new bugs and different incompatibilities every time a new version is issued.

please provide sample scripts and possibly errors in whatever shell you use if you want better help. if you use complex scripts with bash, please also provide bash's version (well at least 2.x or 3.x as the bugs are very different from one version to the next)
0
 
LVL 35

Expert Comment

by:Mark Geerlings
ID: 39178078
Another possible reason for failures via cron, when the same command works interactively is because cron jobs do not automatically inherit the same environment that you get when you log in interactively.   Cron doesn't run the /home/[user]/.bashrc and /home/[user].bash_profile files.  I usually set up a shell script that contains any setup or environment commands from .bashrc and .bash_profile that Oracle jobs will need.  Then I call this script first (with "dot space filename" syntax) in shell scripts that I schedule via cron to run Oracle-related jobs

For example, I create a file named "set_ora.sh" that contains any path, setup or environment variables that Oracle jobs will need when called via cron.  That I can create a shell script to do an Oracle backup using Oracle's RMAN utility something like this, and schedule that in cron:

#!/bin/bash
cd /home/oracle
. set_ora.sh
$ORACLE_HOME/bin/rman [parameters...]
0
 
LVL 27

Expert Comment

by:skullnobrains
ID: 39179352
can you post the script or the script part that spawns "rman_full_backup" ?
0
 
LVL 62

Expert Comment

by:gheist
ID: 39180682
The comman line you run is:
/u01/app/oracle/backup/rman/rman_backup_modified_new.sh 0 /dev/null

script cpmplains as it does not know parameter /dev/null

small mistype huh
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question