LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 10-22-2008, 02:56 PM   #1
wrabanal
LQ Newbie
 
Registered: Oct 2008
Posts: 1

Rep: Reputation: 0
Post Problems with user environments when run cron


Hi,
I have a user Oracle in the Server Suse 10, the user environments put in .profile.

The User Oracle have few cron but and this cron execute scripts RMAN backup.

The output about cron is

Subject: Cron <oracle@db10gserver> sh /u01/backup/scripts/testeo.sh 2>&1 >> /u01/backup/scripts/logs/testeo_rman.log
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/home/oracle>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=oracle>
X-Cron-Env: <USER=oracle>
Message-Id: <20081021181701.37CF21684D6@db10gserver.uoct.cl>
Date: Tue, 21 Oct 2008 15:17:01 -0300 (CLST)
': not a valid identifiero.sh: line 1: export: `
Message file RMAN<lang>.msb not found
Verify that ORACLE_HOME is set properly

The environment is in the script but The Cron take another environment.
i thinks the problem is the environment about user Oracle,

When one cron is executed, what bash is executed similar a .profile when one user logon on server ?

Regards,
Walter


The cron line

10 0 * * 1,3,5 /backup/scripts/incremental_backup_rman.sh 2>&1 >> /backup/scripts/logs/incremental_backup_rman.log

The Script RMAN

#!/bin/sh
export ORACLE_HOME=/u01/app/oracle/product/10.2.0/db_1
export ORACLE_SID=censo
export PATH=$ORACLE_HOME/bin:$PATH
rman target=/ << EOF
RUN {
backup incremental level 1 cumulative tag '%TAG_Level1' database;
backup tag '%TAG_ARCHIVELOG' archivelog all not backed up delete all input;
}
EXIT;
EOF


S.O Suse 10.

Regards,
Walter

Last edited by wrabanal; 10-22-2008 at 03:36 PM.
 
Old 10-22-2008, 03:07 PM   #2
jan61
Member
 
Registered: Jun 2008
Posts: 235

Rep: Reputation: 46
Moin,

cron does not execute the user's profiles and has an environment different to a login shell. First you should not start a shell script using "sh /path/to/script", you should explicitely specify the shell to use: "/bin/bash /path/to/script" and you should define the complete environment you need within the script (you can source the user's profiles: ". /home/oracle/.bashrc" for example).

Jan
 
Old 10-22-2008, 08:59 PM   #3
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,311

Rep: Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040
Quote:
First you should not start a shell script using "sh /path/to/script",
Actually, he didn't, he's got the specified shell as the first line of the script which is fine.
I agree he needs to add or source the correct env inside the shell script.
 
Old 10-23-2008, 05:09 PM   #4
jan61
Member
 
Registered: Jun 2008
Posts: 235

Rep: Reputation: 46
Moin,

Quote:
Originally Posted by chrism01 View Post
Actually, he didn't, he's got the specified shell as the first line of the script which is fine.
on my system /bin/sh is a link to bash - it should be the standard. But you don't know that for sure. It could be bourne shell or korn shell or C shell and then you'll get into trouble if you request a specific shell. That's why I recommend to define exactly, which shell to use.

Another point: Even if you define the shell at the shebang line - if you call the script using sh /path/to/script, the calling shell executes the script and doesn't take care of the shebang line:
Code:
jan@jack:~/tmp> cat bash.sh
#! /bin/bash
for ((i=1;i<4;i++));  do
  echo $i
done

jan@jack:~/tmp> sh ./bash.sh
1
2
3
jan@jack:~/tmp> ksh ./bash.sh
./bash.sh[2]: syntax error: `((' unexpected
So, if the cron environment doesn't find your expected shell first in the path, you'll get into trouble again.

Jan
 
  


Reply

Tags
cron


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
cron job as a non-privileged user do not run chakkerz Linux - General 5 06-03-2008 09:28 PM
User Cron Jobs Won't Run - Pulling Hair Out rhugga Linux - Enterprise 2 08-06-2007 12:52 AM
can run script from my user but not with cron beeblequix Linux - Enterprise 2 04-13-2007 11:22 AM
why do programs only run in particular environments? wds Linux - Newbie 3 01-30-2007 04:50 PM
Can't run cron jobs as user, only root Kropotkin Linux - Newbie 5 11-10-2004 10:30 AM


All times are GMT -5. The time now is 12:38 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration