RMAN commands inside crontab shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting RMAN commands inside crontab shell script
# 1  
Old 03-04-2013
RMAN commands inside crontab shell script

Hello

I'm trying to write simple script to delete archive logs for RMAN, unfortunately it's not working, I tried two way to do that:

Code:
#!/bin/ksh
echo "Start ....."
rman target=/ << EOF
RUN {
  delete force noprompt archivelog until time 'sysdate-10';
}
EXIT;
EOF
echo "END ..."
echo `date`

the other way was

I wrote RMAN commands in separate file:

Code:
vi /scriprts/rman_c.txt
RUN {
  delete force noprompt archivelog until time 'sysdate-10';
}
EXIT;

Then I called those commands from shell script

Code:
#!/bin/ksh
echo "Start ....."
rman target=/ @rman_c.txt
echo "END ..."
echo `date`

When I run the script it will work in command line, but when I use it as crontab job it will never connect to RMAN

the output log for crontab job script will be:

Code:
cat /tmp/log.txt
 Start .....
END ...
Mon Mar 4 12:09:01 AST 2013

# 2  
Old 03-06-2013
Do you get any errors? Running in 'cron' is not like logging in, more like running "ssh user@ost ksh". Your environment is not set up, so commands that work interactively or with a controlling terminal may not run. Usually, the script starts with something like ". ./.profile </dev/null >/dev/null 2>&1" to get environment, but if you need a tty, tougher, maybe "ssh -tt localhost ' ./.profile </dev/null >/dev/null 2>&1;cmd args ....".

Also, 'cron' can discard or email stdout and stderr, so redirect them right off in the crontab line, and maybe everything inside the script as well:
Code:
(...) >>cron_xxx_log.$( date '+%Y-%m-%d' ) 2>&1

Be careful as '%' is meta in crontab, so it is hard to use date there. I wrote a 'date' wrapper that used '~' for '%', just for 'cron'. If the scripts that cron calls all immediately redirect their logging, you can use a shared log for all crontab lines that is fixed, as it is normally empty. Set up good logging. You deserve it. It is a great investment in your development speed (fast debug) and future (prod support much later).

Last edited by DGPickett; 03-06-2013 at 03:18 PM..
# 3  
Old 03-06-2013
In addition to what DGPickett said, I would suggest to be explicit regarding the absolute path to the rman executable:
export the ORACLE_HOME variable and use "$ORACLE_HOME"/bin/rman instead of just rman.
On some Linux distributions, for example, you may have more than one executable file named rman
(you could have /usr/bin/X11/rman for instance).
# 4  
Old 03-06-2013
Yes, the same environment that worked it interactively, including a $PATH to the right rman and any $OTHER_THINGS like that.
# 5  
Old 03-07-2013
try souring the ~/.profile for oracle user and as suggested by radoulov, DHPickett , use absolute path names.
# 6  
Old 03-07-2013
Thanks a lot everybody for help.

It works after I used as below


Code:
. 
less /export/home/oracle/Tools/rman0.ksh
/export/home/oracle/.profile
rman target / nocatalog @/export/home/oracle/Tools/rman0.rcv log="/u04/rmanbkup/log/rman-`date  +%y%m%d`.log"

# 7  
Old 03-07-2013
Welcome to the land of ssh, cron and at. When you log in, you are given environment by layers of files. If a pid runs not logged in, it has to build environment. Full absolute paths are just a weak stopgap for a bigger symptom. What if you need a dynamic lib*.so and your LD_LIBRARY_PATH is unset? Oracle has its own env needs.

If you want something simple, you can just "set >.runtime_env" and clone your environment. Some of it may be too specific to your login to be appropriate; it will be 'too much'. I do 'if' sections in my .profile for 'only if tty present', 'only if X', 'only if ksh' or 'only if bash', so it prunes itself down in cron, sh, ssh.
This User Gave Thanks to DGPickett For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Why commands inside bash script lost effectiveness?

Hi, I have a bash script to run many system commands on CentOS machine, but I am puzzled by some commands had no effect on parent environment. For example, I want to refresh the desktop xdg menu when some processes added or deleted items from desktop xdg menu. If I run "killall gnome-panel"... (4 Replies)
Discussion started by: hce
4 Replies

2. Shell Programming and Scripting

RMAN script gives error

Hi, I have the following RMAN incremental shell script: # !/bin/bash export ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1 export ORACLE_SID=ORCL export PATH=$PATH:${ORACLE_HOME}/bin rman target=/ << EOF run { allocate channel d1 type disk FORMAT... (3 Replies)
Discussion started by: royalibrahim
3 Replies

3. Shell Programming and Scripting

[Solved] Usage of shell commands inside a C program

Hi I have a program int main(int srgc, char *argv) { for(int i=1; i<50; i++) { system("dd if=/dev/zero of=file$i bs=1024 count=$i"); } return 0; } My doubt is how to use the "$i" value inside C code Please help (2 Replies)
Discussion started by: Priya Amaresh
2 Replies

4. Shell Programming and Scripting

Executing multiple ssh commands inside a shell simultaneously

I would like to execute a commands in four different servers through ssh at a single instance(simultaneously). Below are the details with examples, ssh user1@server1 "grep xxxx logs" ssh user1@server2 "grep xxxx logs" ssh user1@server3 "grep xxxx logs" Each statement will take some... (4 Replies)
Discussion started by: Amutha
4 Replies

5. Shell Programming and Scripting

rman script

Hi, Can anyone provide me with RMAN script for taking backup to tape and restoring the same from tape. Thanks (0 Replies)
Discussion started by: chetansingh23
0 Replies

6. Shell Programming and Scripting

Unix commands failing inside the shell script

When my script deals with large input files like 22Gb or 18 GB the basic commands like sort or join fails when run from inside the shell scripts. Can there be any specific reason for this? For e.g. sort -u -t "," -k1,1 a.csv > a.csv.uniq" sort -u -t "," -k1,1 b.csv > b.csv.uniq" The... (3 Replies)
Discussion started by: esha
3 Replies

7. Shell Programming and Scripting

How to use ftp commands inside shell script? Help please

Dears, I'm new in shell scripting and i need your help, i would like to know how can i create a script to ftp to a certain unix/linux machine/server IP address and get a file for example without user intervention? How can i force the script to use a certain username and password to access this... (4 Replies)
Discussion started by: Dendany83
4 Replies

8. Shell Programming and Scripting

invoking a shell script inside cgi shell script

Hi, I have an HTML form through which I get some text as input. i need to run a shell script say script.sh inside a perl-cgi script named main_cgi.sh on the form input. I want to write the contents of the form in a file and then perform some command line operations like grep, cat on the text... (2 Replies)
Discussion started by: smriti_shridhar
2 Replies

9. Shell Programming and Scripting

Shell Script for RMAN Backup

Hi Experts, Can anyone help me to write shell script for taking backup with RMAN in oracle 9i or suggests me any site which has this kind of scripts Thanks shaan (1 Reply)
Discussion started by: shaan_dmp
1 Replies

10. Shell Programming and Scripting

How to run unix commands in a new shell inside a shell script?

Hi , I am having one situation in which I need to run some simple unix commands after doing "chroot" command in a shell script. Which in turn creates a new shell. So scenario is that - I need to have one shell script which is ran as a part of crontab - in this shell script I need to do a... (2 Replies)
Discussion started by: hkapil
2 Replies
Login or Register to Ask a Question