Solved

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

Posted on 2013-05-17
11
462 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 

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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
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
Via a live example, show how to take different types of Oracle backups using RMAN.
Suggested Courses

751 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