LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   Problems with user environments when run cron (http://www.linuxquestions.org/questions/linux-general-1/problems-with-user-environments-when-run-cron-678370/)

wrabanal 10-22-2008 02:56 PM

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

jan61 10-22-2008 03:07 PM

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

chrism01 10-22-2008 08:59 PM

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.

jan61 10-23-2008 05:09 PM

Moin,

Quote:

Originally Posted by chrism01 (Post 3319224)
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


All times are GMT -5. The time now is 04:13 PM.