LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 05-19-2010, 10:56 AM   #1
sam4classic
LQ Newbie
 
Registered: May 2010
Posts: 3

Rep: Reputation: 0
Question Problem with Crontab


Hello, I am trying to run a script using crontab. These are the jobs I have done and errors am encountering:

in the /export/home/oracle9i , I created a crontab file "mycrontab" and the details were:

#!/bin/bash
50 14 * * 1-5 bash cd /opt/oracle9i/app/oracle/product/9.2.0/oradata/bin/mycronexport

which means at 2:50pm from Mon to Fri it should change directory to /opt/oracle9i/app/oracle/product/9.2.0/oradata/bin and execute the script "mycronexport". mycronexport is a script that has the command to execute the exp utility in linux/unix for export.

This is the content of the mycronexport script:
echo "EXPORTING THE IN-HOUSE-APPLICATION DATA OF SMS"
#!/bin/bash
./exp sms/<password>@<database_alias> statistics=none
mv expdat.dmp /data2/in_hse_apps_exports/<application_name>.dmp

After the set time I checked my mail and the script wasn't executed. These were some errors I encoutered:

"cannot execute binary data" or nothing appears at all. At times I change the mycrontab file parameters by for e.g.:

#!/bin/bash
50 14 * * 1-5 bash cd /opt/oracle9i/app/oracle/product/9.2.0/oradata/bin
51 14 * * 1-5 bash mycronexport

and I'm still getting errors like "cannot open mycronexport" or mycronexport is not a directory; especially. However when cd /opt/oracle9i/app/oracle/product/9.2.0/oradata/bin and call the script, it works perfectly. Why can't I call it with the crontab file?

Please help me out with this one. I hope the description is very detailed enough to enable you give the best of solutions.

Regards,
Sam4classic
 
Old 05-19-2010, 11:01 AM   #2
ctkroeker
Senior Member
 
Registered: May 2005
Posts: 1,565
Blog Entries: 1

Rep: Reputation: 50
Welcome to LQ!

Please give your threads title related to your problem, such as "Problem with Crontab".

Your problem is that
Code:
bash cd /opt/oracle9i/app/oracle/product/9.2.0/oradata/bin/mycronexport
isn't executing your script.

Make your script executable
Code:
chmod a+x /opt/oracle9i/app/oracle/product/9.2.0/oradata/bin/mycronexport
And just tell cron to
Code:
/bin/sh /opt/oracle9i/app/oracle/product/9.2.0/oradata/bin/mycronexport
That should do it. No need to CD.

Last edited by ctkroeker; 05-19-2010 at 11:02 AM. Reason: typo
 
Old 05-19-2010, 11:02 AM   #3
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297
Hello and Welcome to LinuxQuestions,

First of all, don't use words like Urgent and especially not in a title. It's not very descriptive, doesn't tell us anything about your problem/question and is considered pretty rude since all of us here are volunteers. If you really want it urgent then hire and pay someone.

That being said, I might be wrong but I thought you just could put one command in a line in crontab, and you're putting two in (cd and your script). You don't have to put the change directory command in that line since you're stating the full path. Delete the 'cd' part and see if it runs then.

Kind regards,

Eric
 
Old 05-20-2010, 08:20 AM   #4
sam4classic
LQ Newbie
 
Registered: May 2010
Posts: 3

Original Poster
Rep: Reputation: 0
Question Problem with Crontab ./exp and mv in a script accessed by the crontab file

Hello,
Thanks so much for your assistance and time taken to help me solve this problem. First of all, accept my apology for not stating a good title for my thread.

The crontab file "mycrontab" executed the script but generated some errors which I suspect might be coming from the "/opt/oracle/app/oracle9i/product/9.2.0/oradata/bin/mycronexport" file.

In the script I want the export utility to execute and export the expdat.dmp file and move it into a directory "/data2/in_hse_apps_exports/<application_name>.dmp" But these are the errors generated:

Your "cron" job on accs02
/bin/sh /opt/oracle9i/app/oracle/product/9.2.0/oradata/bin/mycronexport

produced the following output:

/opt/oracle9i/app/oracle/product/9.2.0/oradata/bin/mycronexport: ./exp: not found
mv: cannot access expdat.dmp

Which means the program cannot read and execute ./exp and the command mv from the script; even though I have chmod a+x /opt/oracle9i/app/oracle/product/9.2.0/oradata/bin/mycronexport. I believe somebody can give me a very simple way of going around this problem. Thank you in advance, Eric and co.

Regards,
sam4classic

Last edited by sam4classic; 05-20-2010 at 08:23 AM. Reason: Added more details
 
Old 05-20-2010, 08:39 AM   #5
ctkroeker
Senior Member
 
Registered: May 2005
Posts: 1,565
Blog Entries: 1

Rep: Reputation: 50
What is ./exp? Another script you wrote? Or are you just misusing the "export" command?
As for the mv command, you probably need to indicate where expdat.dmp actually is, example:
Code:
mv /home/user/expdat.dmp /home/user/data2/in_hse_apps_exports/<application_name>.dmp
 
Old 05-20-2010, 08:51 AM   #6
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
Quote:
Originally Posted by sam4classic View Post
The crontab file "mycrontab" executed the script but generated some errors which I suspect might be coming from the "/opt/oracle/app/oracle9i/product/9.2.0/oradata/bin/mycronexport" file.
Oracle shell scripting style is not robust, probably because most scripts are written by DBAs who are not shellscript-sperts. I figure they keep going until it works and stop there.

Oracle shellscripts rely heavily on environment variables and current working directories. This does give flexibility to switch between Oracle versions and database instances but requires that things are set up correctly.

Preamble over, on to a possible solution. Be warned I have no Oracle to test this on or to investigate how things work.

Presuming (please correct if wrong):
  • this cron job is being run for user oracle.
  • /opt/oracle/app/oracle9i/product/9.2.0/oradata/bin/mycronexport is a bash script and has been tested interactively when logged on as oracle with /opt/oracle9i/app/oracle/product/9.2.0/oradata/bin/mycronexport as the current directory.
  • you do not have to answer any questions when logging on as oracle.
Try changing the first line of the script to #!/bin/bash -l. That's a letter l and tells bash to run the login procedure thus setting up the environment in the same way as when you log in as oracle (hence must not be asked questions during login because there is no terminal to read the answers from and cron will stop the job).

Program the script to change to the required directory and to exit if it can't:
Code:
cd /opt/oracle9i/app/oracle/product/9.2.0/oradata/bin/mycronexport || exit 1

Last edited by catkin; 05-20-2010 at 08:54 AM. Reason: sin tacks
 
Old 05-21-2010, 08:32 AM   #7
sam4classic
LQ Newbie
 
Registered: May 2010
Posts: 3

Original Poster
Rep: Reputation: 0
Hello To Ctkroeker and Catkin,

Thanks so much for your effort. The ./exp command here is used to start the export utility; to collect all the required exported data for the In-House-Application. For example: after I have logged on as oracle9i from the SSH Client side, these are displayed:

Last login: Thu May 20 15:07:47 2010 from <IP_Address>
Sun Microsystems Inc. SunOS 5.9 Generic May 2002
-sh: /usr/ccs/bin,: not found
-sh: dbhome: not found
ORACLE_HOME = [] ?

Then I pass this path /opt/oracle9i/app/oracle/product/9.2.0/oradata as the ORACLE_HOME. On hitting the Return key, this is what displays:

SQL*Plus: Release 9.2.0.1.0 - Production on Fri May 21 12:39:57 2010

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.


Connected to:
Oracle9i Enterprise Edition Release 9.2.0.1.0 - 64bit Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.1.0 - Production

SQL>

After database instance has started then I exit from the SQL prompt to the shell prompt

SQL> exit
Disconnected from Oracle9i Enterprise Edition Release 9.2.0.1.0 - 64bit Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.1.0 - Production
$ printenv to see the environment variables

CLASSPATH=/opt/oracle9i/app/oracle/product/9.2.0/oradata/jlib/oembase-9_2_0.jar:/opt/oracle9i/app/oracle/product/9.2.0/oradata/jlib/oemlt-9_2_0.jaremtools-9_2_0.jar
HOME=/export/home/oracle9i
LD_LIBRARY_PATH=/opt/oracle9i/app/oracle/product/9.2.0/oradata/lib32
LD_LIBRARY_PATH_64=/opt/oracle9i/app/oracle/product/9.2.0/oradata/lib
LOGNAME=oracle9i
ORACLE_BASE=/opt/oracle9i/app/oracle
ORACLE_HOME=/opt/oracle9i/app/oracle/product/9.2.0/oradata
ORACLE_SID=ORA_SID
PATH=/usr/bin:/usr/ucb:/etc:.:/opt/oracle9i/app/oracle/product/9.2.0/oradata/bin
SHELL=/bin/sh
TERM=vt100
TNS_ADMIN=/opt/oracle9i/app/oracle/product/9.2.0/oradata/network/admin
TZ=Africa/Accra
USER=oracle9i

From the environment variables, you'll realize that the HOME=/export/home/oracle9i and the ORACLE_HOME=/opt/oracle9i/app/oracle/product/9.2.0/oradata. So I cd $ORACLE_HOME/bin where the exp utility is invoked with ./exp and followed by the In-House-Application name and Password to be exported. In the /bin directory is where I run the export. For example:


./exp apps_name/apps_passwd@ORA_SID statistics=none And by hitting the return key, export of the applicatiion specified begins. After all the tables and data or information in the database based on that particular application have been gathered, the expdat.dmp file is created within the /bin directory. To allow for the next application information to be gathered, I move the expdat.dmp file to a different directory and after renaming it. For example:

mv /data2/in_hse_apps_exports/apps_name.dmp hereby the expdat.dmp file has been renamed and stored in the specified directory.

Code/Command:
$ pwd
/opt/oracle9i/app/oracle/product/9.2.0/oradata/bin
$ ./exp apps_name/apps_passwd@ORA_SID statistics=none
$ mv /data2/in_hse_apps_exports/apps_name.dmp

Whenever I run these commands directly from the /opt/oracle9i/app/oracle/product/9.2.0/oradata/bin directory, no errors are generated, but whenever I use the script, then the errors:

./exp: not found
mv: cannot access expdat.dmp


The Crontab file executing this script is in the /export/home/oracle9i/mycrontab . Here, mycrontab is the name of the crontab file I created.

Brethren, I think I have given you a clearer picture now. So I'm not misusing the export command, but this is the scenario at the moment. I will get back to you as soon as all is set for the time being. I'm still using your advice and directives.

Thank you,
sam4classic

Last edited by sam4classic; 05-21-2010 at 08:34 AM.
 
Old 05-21-2010, 10:23 AM   #8
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
If you can't find "./exp", chances are it's not in the path and/or the directory you're trying to execute it from. Specify the whole path name, like "/usr/local/bin/exp", or something like that. That's good practice for anything that you run from cron, to help you avoid problems like this.
 
Old 05-21-2010, 12:07 PM   #9
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
Quote:
Originally Posted by sam4classic View Post
Brethren, I think I have given you a clearer picture now. So I'm not misusing the export command, but this is the scenario at the moment. I will get back to you as soon as all is set for the time being. I'm still using your advice and directives.
Thanks for the further info. What you describe about what happens when you log on as oracle precludes the #/bin/bash -l suggestion. Please tell us how you progress.
 
Old 05-21-2010, 01:12 PM   #10
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,699

Rep: Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895
To elaborate the . in ./exp is a shortcut for current working directory. In a nutshell to execute programs that are in your current working directory but not in your environment path you would use ./myprogram. FYI you can view you path via the command
echo $PATH

If you try to run ./exp or any program that calls ./exp when the current working directory is not /opt/oracle9i/app/oracle/product/9.2.0/oradata/bin it will fail.

cron has a very limited environment and as already suggested it is always best to include the full path.

This should work I think ...
#!/bin/bash
cd /opt/oracle9i/app/oracle/product/9.2.0/oradata/bin
./exp sms/<password>@<database_alias> statistics=none
mv expdat.dmp /data2/in_hse_apps_exports/<application_name>.dmp
 
  


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
Crontab problem razzera Debian 4 04-07-2010 08:39 AM
crontab problem almon Linux - Newbie 1 10-11-2007 02:27 PM
crontab problem sunnyanthony Linux - Software 1 01-07-2006 04:48 AM
Problem with crontab PierrePau Linux - Software 3 06-28-2004 02:34 PM
crontab problem TomTheNewbie Slackware 1 07-09-2003 07:12 AM

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

All times are GMT -5. The time now is 08:22 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