Solved

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

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

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
 

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 76

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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

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 76

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 26

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 26

Expert Comment

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

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

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.
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

920 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

14 Experts available now in Live!

Get 1:1 Help Now