LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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-12-2004, 06:10 AM   #1
saifee
LQ Newbie
 
Registered: Oct 2004
Location: karachi
Posts: 3

Rep: Reputation: 0
Question 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,
 
Old 10-12-2004, 06:35 AM   #2
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 269Reputation: 269Reputation: 269
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??
 
Old 10-13-2004, 06:42 AM   #3
saifee
LQ Newbie
 
Registered: Oct 2004
Location: karachi
Posts: 3

Original Poster
Rep: Reputation: 0
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
 
Old 10-26-2004, 04:37 PM   #4
jalla
Member
 
Registered: Oct 2003
Posts: 33

Rep: Reputation: Disabled
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.
 
Old 11-15-2004, 04:59 AM   #5
dani81
LQ Newbie
 
Registered: Aug 2004
Posts: 13

Rep: Reputation: 0
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!!!
 
Old 11-15-2004, 06:53 AM   #6
jalla
Member
 
Registered: Oct 2003
Posts: 33

Rep: Reputation: Disabled
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

----------------------------------------------------------
 
Old 12-02-2004, 04:30 PM   #7
saifee
LQ Newbie
 
Registered: Oct 2004
Location: karachi
Posts: 3

Original Poster
Rep: Reputation: 0
hi
its work
when i export the env variable along with
$ORACLE_SID=oracle sid
export $ORACLE_SID

Its work
thanks
 
Old 06-07-2006, 01:41 PM   #8
lbireley
LQ Newbie
 
Registered: Jun 2006
Posts: 1

Rep: Reputation: 0
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
 
Old 09-25-2010, 07:44 AM   #9
rahmtech
LQ Newbie
 
Registered: Sep 2010
Posts: 11

Rep: Reputation: 0
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
 
Old 12-06-2010, 04:54 AM   #10
revanthec
LQ Newbie
 
Registered: Nov 2010
Posts: 3

Rep: Reputation: 0
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
 
Old 12-06-2010, 05:52 AM   #11
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
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.
 
Old 01-29-2012, 09:24 AM   #12
ismail_jh
LQ Newbie
 
Registered: Jan 2012
Posts: 1

Rep: Reputation: Disabled
Lightbulb

Quote:
Originally Posted by saifee View Post
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;
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to pass command-line parameter to shell script? Kropotkin Linux - Newbie 12 07-25-2011 09:24 AM
How to execute a command line in a shell script orgazmo Programming 5 05-09-2005 09:16 AM
shell script works form command line but not form crontab saifee General 1 10-14-2004 10:27 AM
Shell Script to read 500files from the command line saravanan1979 Programming 1 09-22-2004 09:44 AM
how do I copy a whoel folder form one directory to another form the command line? zwyrbla Linux - Newbie 8 08-24-2004 06:40 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 05:58 PM.

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