LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   my database export shell script run from command line but not form crontab (https://www.linuxquestions.org/questions/linux-general-1/my-database-export-shell-script-run-from-command-line-but-not-form-crontab-241653/)

saifee 10-12-2004 06:10 AM

my database export shell script run from command line but not form crontab
 
i am learning linux and shell scripting , i install 9.2.0.1.0 oracle database on my linux 8.5, what i want to automate my oracle database export by crontab daily at night time e.g (4:15 am). i wrote a simple shell shell script (as an oracle user )exp.sh as below and save the script in
/home/oracle/shellprog/ directory.

#/bin/sh
# exporting user schema
ORACLE_HOME=/u02/app/oracle/product/9.2.0.1.0
dt=`date +%Y%m%d`
${ORACLE_HOME}/bin/exp system/oracle owner=scott file=/home/oracle/shellprog/scottexp.$dt

when i execute the exp.sh script form command line its works fine
[oracle@saif oracle]$ . exp.sh
login in as an oracle user i write the following crontab file

15 4 * * * /home/oracle/shellprog/exp.sh

problem is

shell script run form the command lines but not from the crontab via login as an oracle user
i also gave execute permision to exp.sh script

i try several thing to sort this out but did't work i try these things

1- hard code the $ORACLE_HOME in the script
2-include the directory path of the shell script in the .profile of oracle user
3- include the /home/oracle/shellprog path in the /etc/crontab file
4- copy the exp.sh (as a root) script in the /etc/cron.daily and and set the /etc/crontab as a root user like this

my /etc/crontab file is as following

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/home/oracle/shellprog:/u02/app/oracle/product/9.2.0.1.0/bin:/home/oracle
MAILTO=root
HOME=/

# run-parts
01 * * * * root run-parts /etc/cron.hourly
20 13 * * * oracle /home/oracle/shellprog/login.sh run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly

i also change the user oracle to root in the /etc/crontab file but same result

all those steps results in negative , any one have solution
thanks in advance

saif,

trickykid 10-12-2004 06:35 AM

If your script runs from the command, its most likely how you have it setup to run as a cron. Have you checked your logs to see why its failing? How are you running it from the command? Is the file executable? Are the permissions correct on it? More details please?

And what is Linux 8.5?? I don't know of any distro that is currently using that version number or ever has used that number??

saifee 10-13-2004 06:42 AM

i mistyped the version of linux correct version is 8.0

the shell scriopt has execute permision for every one
[oracle@saif shellprog]$ pwd
/home/oracle/shellprog
[oracle@saif shellprog]$ chmod +x exp.sh
permision for dir are as below
-rwxrwxr-x 1 oracle oinstall 471 Oct 10 22:38 exp.sh

when i run the script from here it work
[oracle@saif shellprog]$ . exp.sh

note: i have also write couple of shell script(login.sh) to startup my oracle database and to shut down(shut.sh) autoamatically
but having the same prob, i am sending you the couple of line of my log file from


[root@saif log]# pwd
/var/log
[root@saif log]# vi cron
Oct 13 16:26:00 saif crond[756]: (tmp.1788) ORPHAN (no passwd entry)
Oct 13 16:26:00 saif crond[756]: (tmp.1964) ORPHAN (no passwd entry)
Oct 13 16:26:00 saif crond[756]: (tmp.2539) ORPHAN (no passwd entry)
Oct 13 16:30:00 saif CROND[1523]: (oracle) CMD (/home/oracle/shellprog/login.sh run-parts /etc/cron.daily)
Oct 13 16:30:00 saif CROND[1524]: (oracle) CMD (/home/oracle/shellprog/exp.sh)
Oct 13 16:30:02 saif crontab[1530]: (oracle) LIST (oracle)

let me know is this the right place to find the log or not
i took this line when i changed my crontab file and try to run the export at 16:30

[oracle@saif shellprog]$ crontab -l
# DO NOT EDIT THIS FILE - edit the master and reinstall.
# (/tmp/crontab.1511 installed on Wed Oct 13 16:24:26 2004)
# (Cron version -- $Id: crontab.c,v 2.13 1994/01/17 03:20:37 vixie Exp $)
30 16 * * * /home/oracle/shellprog/exp.sh

thanks for your interest
waiting for reply

jalla 10-26-2004 04:37 PM

i also had the same problem but if you set all env. variables it works fine. try to make cron send the log to you (at least untill it works as it should) so that its easier to trace the error.
I set all env. variables in /home/oracle/.bashrc.

dani81 11-15-2004 04:59 AM

I have the same problem :(

I made a script wireless.sh and when i start it from bash is works. But when cron wants to start it, it doesn't work !

telnet xxx.xxx.xxx.xxx

su

/root/wireless.sh <- works

crontab -e

17 * * * * /root/wireless.sh

doesn't work!!!

jalla 11-15-2004 06:53 AM

have you exported all env. variables?

---------------

export LD_ASSUME_KERNEL=2.4.1
export ORACLE_BASE=/u02/app/oracle
export ORACLE_HOME=/u02/app/oracle/product/9.2.0
export ORACLE_SID=production
export ORACLE_TERM=xterm

export NLS_LANG=AMERICAN_AMERICA.WE8ISO8859P1
export ORA_NLS33=$ORACLE_HOME/ocommon/nls/admin/data
LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
export LD_LIBRARY_PATH

# Set shell search paths
export PATH=$PATH:$ORACLE_HOME/bin

----------------------------------------------------------

saifee 12-02-2004 04:30 PM

hi
its work
when i export the env variable along with
$ORACLE_SID=oracle sid
export $ORACLE_SID

Its work
thanks

lbireley 06-07-2006 01:41 PM

Since cron invokes a subshell from your $HOME directory, it does not run your .profile so to have your shell program behave with cron as it does when you invoke it from the command line here are 2 simple additions to the start of your shell script that will take care of it without redundancies.

. $HOME/.profile
#Reloads the user profile so its variables are available in cron job
export ORACLE_SID=sid #substitute your sid here
#Makes environmental variable available to child processes

rahmtech 09-25-2010 07:44 AM

cron jobs
 
I have had the same issue. I know this is an old post, but these old posts sometimes answer my many questions.

I cant explain why it is the way it is, but after checking permissions, checking code for errors, creating test scripts, etc, I found that the reason my scripts were not running when envoked by cron was due to their .sh file extension.

As soon as I removed the .sh file extension from my scripts, they all began working with cron as expected.

If anyone knows why this is, please share.

uname -a
Linux nixbox.local 2.6.28-19-generic #65-Ubuntu SMP Thu Sep 16 14:14:28 UTC 2010 i686 GNU/Linux

Chris Rahm
RahmTech Computing

revanthec 12-06-2010 04:54 AM

I have the same problem with a sheel script, i have sett all the environment variables.
The Job of the script is to run perl process , the same script works from the command line, but wont work form cron.


#!/bin/sh
#set -x

. /etc/profile

export MDX_HOME=/home/entsms
source /home/entsms/.bash_profile
export PERL5LIB=/home/entsms/program
export USER=entsms
export ORACLE_TERM=386
export LOGNAME=entsms
export ORA_NLS=/oracle/product/102/db_1/nls/data/
export HOSTNAME=drvl024.mtnirancell.ir
export JAVA_HOME=/usr/java/j2sdk1.4.0_03
export LANG=en_US.UTF-8
export NLS_NCHAR=AL32UTF8
export NLS_LANG=AMERICAN_AMERICA.AL32UTF8
export ORACLE_SID=sid
export ORACLE_BASE=/oracle
export ORACLE_HOME=/oracle/product/102/db_1
export LD_LIBRARY_PATH=/oracle/product/102/db_1/lib:/lib

catkin 12-06-2010 05:52 AM

Hey Chris and revanthec, best you start your own threads instead of necroposting; it devalues the original thread and gets confusing when multiple questions are answered in the same thread. You can include a link to this thread if you think it would be helpful.

Chris, the phenomenon you describe doesn't make immediate sense; it would be great to have some more information so we can figure it out.

ismail_jh 01-29-2012 09:24 AM

Quote:

Originally Posted by saifee (Post 1229200)
15 4 * * * /home/oracle/shellprog/exp.sh
saif,

You should "cd" to the script directory before executing it...

try this in "crontab", it's work for me

15 4 * * * cd /home/oracle/shellprog/; ./exp.sh;


All times are GMT -5. The time now is 11:39 AM.