LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 11-30-2017, 02:38 AM   #1
Natarajachar
LQ Newbie
 
Registered: Oct 2016
Posts: 18

Rep: Reputation: Disabled
Crontab not working as expected for one script


Hi guys,

I have defined cronjob in my SLES10 server which runs RMAN for archival of archive logs. The crontab looks like this:

00,20,40 * * * * /u02/backup/rman/rman_archive_del.sh>>/u02/backup/rman/rman_archive_del1.log

When I run the script manually, the script will invoke RMAN and do the job well but when I leave it for crontab to run it, it is not invoking RMAN itself.

The same script is working fine in another linux server.

Thanks&Regards,
Natraj
 
Old 11-30-2017, 02:45 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,840

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
I think this is the usual crontab issue:
1. use full path in your script to invoke rman (and others)
2. save stderr somewhere to see what's happened, otherwise we can only guess.
 
Old 11-30-2017, 03:55 AM   #3
Natarajachar
LQ Newbie
 
Registered: Oct 2016
Posts: 18

Original Poster
Rep: Reputation: Disabled
Hi,

Thanks for the reply.
I added the path of rman. Still the issue remains.

Regards,
Natraj
Attached Files
File Type: txt script.txt (496 Bytes, 44 views)
File Type: txt rman log.txt (938 Bytes, 32 views)
 
Old 11-30-2017, 04:02 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,840

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
you can insert set -xv at the beginning of the script to see what's happening.
And also use bash to start your script:
Code:
00,20,40 * * * * /bin/bash /u02/backup/rman/rman_archive_del.sh>>/u02/backup/rman/rman_archive_del1.log
 
Old 12-01-2017, 12:35 AM   #5
Natarajachar
LQ Newbie
 
Registered: Oct 2016
Posts: 18

Original Poster
Rep: Reputation: Disabled
Thanks for the reply.
The same script is running well on another server but it is not running on this machine. Please help.
 
Old 12-01-2017, 12:38 AM   #6
Natarajachar
LQ Newbie
 
Registered: Oct 2016
Posts: 18

Original Poster
Rep: Reputation: Disabled
Hi,

After making the changes as suggested by you previously, the cronjob is invoking RMAN. But it is throwing error when it runs automatically.

***********Archive file deletion started at Fri Dec 1 14:50:00 IST 2017***********


Recovery Manager: Release 10.1.0.4.2 - Production

Copyright (c) 1995, 2004, Oracle. All rights reserved.

RMAN>
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
ORA-12162: TNS:net service name is incorrectly specified

RMAN>
connected to recovery catalog database

RMAN> RMAN> RMAN> RMAN> RMAN> The archival process ended at Fri Dec 1 14:50:00 IST 2017

Where as when I run thye same script manually, it works fine.

***********Archive file deletion started at Fri Dec 1 14:51:02 IST 2017***********


Recovery Manager: Release 10.1.0.4.2 - Production

Copyright (c) 1995, 2004, Oracle. All rights reserved.

RMAN>
connected to target database: CONPRDDB (DBID=2379791943)

RMAN>
connected to recovery catalog database

RMAN> RMAN> RMAN> RMAN> RMAN> The archival process ended at Fri Dec 1 14:51:10 IST 2017

Regards,
Natraj
 
Old 12-05-2017, 12:55 PM   #7
voleg
Member
 
Registered: Oct 2013
Distribution: RedHat CentOS Fedora SuSE
Posts: 354

Rep: Reputation: 51
Cron run its jobs in so called "sanitized" environment. You can read about this in it's manual.
You should source your .bashrc (or .profile or what suits) at beginning of script.
 
1 members found this post helpful.
Old 12-07-2017, 09:59 AM   #8
dlopen
LQ Newbie
 
Registered: Dec 2017
Posts: 3

Rep: Reputation: Disabled
I would insert debug statements at the beginning of the script:

date >> /path-to-log
set >> /path-to-log

And then compare environment variables when run manually and via cron.
 
Old 12-08-2017, 03:40 PM   #9
dfreybur
LQ Newbie
 
Registered: Aug 2017
Location: Austin, TX, US
Posts: 11

Rep: Reputation: Disabled
The script finds all of the binaries. Look closely at the error message in the log you posted -

ORA-12162: TNS:net service name is incorrectly specified

That means your tnsnames.ora file is missing, does not contain the SID connection string, is in the wrong directory, is not readable by the user running the crontab.
 
Old 12-26-2017, 04:17 AM   #10
Natarajachar
LQ Newbie
 
Registered: Oct 2016
Posts: 18

Original Poster
Rep: Reputation: Disabled
Hi guys,

Thanks for the replies. I was out of town for some days.
When I run the script, it finishes normal but when I let the crontab run the script it goes error.

RMAN>
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
ORA-12162: TNS:net service name is incorrectly specified

Please suggest.

Thanks&regards,
Natraj
 
Old 12-26-2017, 04:21 AM   #11
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,840

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
see post #9, there are a lot of tips. Did you check all of them? Please post the result.
 
Old 12-26-2017, 09:47 AM   #12
dfreybur
LQ Newbie
 
Registered: Aug 2017
Location: Austin, TX, US
Posts: 11

Rep: Reputation: Disabled
Quote:
Originally Posted by Natarajachar View Post
When I run the script, it finishes normal but when I let the crontab run the script it goes error.
Checking that you are aware there are environment differences between an interactive command and a command run by crontab. Not all of the setup in .bash_profile gets run. Plus anything you typo interactively, like setting your oracle environment, don't happen. Find those differences and add them to your script.

Quote:
ORA-12162: TNS:net service name is incorrectly specified
Error messages matter. Error messages have meaning. Read them carefully. This says your Oracle environment variables aren't set. Which is expected for a crontab run.

Let's see the lines of your script that set ORACLE_SID, ORACLE_BASE, ORACLE_HOME. Because those variables do need to be set in your script as it's not being run interactively.
 
Old 12-26-2017, 10:20 AM   #13
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,634

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by Natarajachar View Post
Hi guys,
Thanks for the replies. I was out of town for some days. When I run the script, it finishes normal but when I let the crontab run the script it goes error.

RMAN>
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
ORA-12162: TNS:net service name is incorrectly specified

Please suggest.
This sounds *VERY* familiar:
https://www.linuxquestions.org/quest...ab-4175603618/

You've been working with Oracle for some time now...have you contacted them for assistance with your scripts??? Have you looked at any of the MANY examples you can find by putting "how to run an rman script through cron on linux" into Google?? Things such as:
https://oracle-base.com/articles/mis...hell-scripting

As you were told before, you need to specify these variables in your script. Are you???
 
1 members found this post helpful.
Old 12-27-2017, 02:23 AM   #14
Natarajachar
LQ Newbie
 
Registered: Oct 2016
Posts: 18

Original Poster
Rep: Reputation: Disabled
The following is the script I wrote:

#!/bin/bash

echo "***********Archive file deletion started at `date`***********"
echo " "
export ORACLE_HOME=/u01/oracle_home/contentdb
#cd $ORACLE_HOME
/u01/oracle_home/contentdb/bin/rman <<EOF
connect target /;
connect CATALOG cat/catalog@conprddb;
spool msglog to '/u02/backup/log/rman_archive_del_new.log'
change archivelog all crosscheck;
delete noprompt expired archivelog all;

exit;
EOF
echo "The archival process ended at `date`">>/u02/backup/rman/rman_archive_del1.log
 
Old 12-27-2017, 03:57 AM   #15
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,840

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
this was the first hit using duckduckgo: http://www.dba-oracle.com/t_ora_1216...rvice_name.htm

Posting a script is useless. You need to explain if you have tried it, what's happened, what was expected ... The script itself is not enough to go further.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash script not working as expected when executed at startup kuhnto Linux - Newbie 8 09-26-2017 08:00 PM
[SOLVED] sudo not working as expected on custom script. crwdawg Linux - Security 8 01-31-2013 06:27 AM
[SOLVED] rsyslog upstart script not working as expected grail Ubuntu 3 03-23-2011 07:47 PM
Wireless script not working as expected SlowCoder Linux - General 6 05-24-2008 07:06 AM
Crontab not working as expected nro Linux - Newbie 7 08-29-2005 12:56 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 03:28 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration