Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 468
  • Last Modified:

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

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
sk0227
Asked:
sk0227
  • 4
  • 3
  • 2
  • +2
1 Solution
 
slightwv (䄆 Netminder) Commented:
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
 
sk0227Author Commented:
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
 
slightwv (䄆 Netminder) Commented:
>>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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
sk0227Author Commented:
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
 
slightwv (䄆 Netminder) Commented:
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
 
sk0227Author Commented:
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
 
slightwv (䄆 Netminder) Commented:
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
 
skullnobrainsCommented:
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
 
Mark GeerlingsDatabase AdministratorCommented:
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
 
skullnobrainsCommented:
can you post the script or the script part that spawns "rman_full_backup" ?
0
 
gheistCommented:
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 Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now