Solved

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

Posted on 2013-05-17
11
457 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 76

Expert Comment

by:slightwv (䄆 Netminder)
Comment Utility
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
Comment Utility
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 76

Expert Comment

by:slightwv (䄆 Netminder)
Comment Utility
>>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
 

Author Comment

by:sk0227
Comment Utility
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 76

Expert Comment

by:slightwv (䄆 Netminder)
Comment Utility
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:sk0227
Comment Utility
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 76

Accepted Solution

by:
slightwv (䄆 Netminder) earned 500 total points
Comment Utility
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 26

Expert Comment

by:skullnobrains
Comment Utility
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 34

Expert Comment

by:Mark Geerlings
Comment Utility
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 26

Expert Comment

by:skullnobrains
Comment Utility
can you post the script or the script part that spawns "rman_full_backup" ?
0
 
LVL 61

Expert Comment

by:gheist
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now