java errors when calling from cron


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting java errors when calling from cron
# 1  
Old 11-15-2002
Question java errors when calling from cron

I am more or less new to using cron, and I am trying to automate a log cleaning system I have made. The system basically cleans through WWW logs that are mounted on an NFS and creates text files for entry into a local PostgreSQL DB.

For the past year I have been running the various scripts and programs I have created from the terminal daily. Everything worked just fine. However, when I rely on cron I now I find I can not insert into my PostgreSQL DB using its JAVA interface. I get the following errors:

Exception in thread "main" java.lang.NoClassDefFoundError: /Users/admin/LOGS/Insert_data

The flow of the insert routine that I use runs as follows:

01_insert_data.csh -> 01_insert_data.pl -> Insert_data.class
(call one site at a time) (lists up non-inserted files) (inserts data into DB)

What is the difference between running appli from the terminal and running appli from the cron? What gets "lost" with cron that would be nomally found on the terminal?
# 2  
Old 11-16-2002
May be as simple as not using absolute paths or not exporting env. variables

most differences in behavior we see between cron running a job and manual runs is because of differences in path setting...

it is always imperative to use absolute paths (starting from /) in all the directory paths in your script...

similarly I hope that you export all the relevant environment variables (like PATH etc) in the very beginning of your shell script... if you run a script manually it will inherit all the env. variables of your logon shell (some of them may be set in your .profile).. if you run a script using cron it will inherit all the cron user's env. variables... you need to ensure within the script that all required env. variables are explicitly set and exported, so that these hold the same values for the subsequent commands using them - both in cron and manual modes...

the java exception you show indicates that a java class was not found in the class path...

Hope this helps...

Cheers!
Vishnu.
# 3  
Old 11-17-2002
Vishnu

Thanks for the info. I dealt with the absolute path bit as soon as I had run the script one time, so absolute paths should not be the issue here anymore...that is unless I have overlooked something.

I am now working on the env. variables bit. I have tried all sorts of combinations - put information concerning java's home into both CLASSPATH and PATH. I have set CLASSPATH and PATH in .tcshrc as well as in the sell script that starts everything moving. Yet I end up with the same error.

It's really a bit frustrating! So, what I have decided to do is create a HELLO WORLD java program and call it directly from the C shell, eliminating for the time being perl which enters the picture between CSH and JAVA in the log cleanning set up I am trying to run from cron.

m(_ _)m
# 4  
Old 11-18-2002
Bug Just a bit of follow up...

I had been under the impression that trouble I encountered when trying to run my Insert_data JAVA class(application or whatever) can from my shell's ENV not being set correctly. I tried everything! I set CLASSPATH and PATH in .tcshrc . In the initial C SHELL script that is called from cron, I added things like ...

setenv JAVA_HOME_R "/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Classes"
set classpath=($JAVA_HOME_R/classes.jar $JAVA_HOME_R/postgresql.jar)

You name it I tried it, but nothing worked.

What I found was it had nothing to do with setting my shells ENV (i.e. PATH CLASSPATH and such). Instead, this turned out to be entirely a JAVA side problem/solution. It was as simple as the following.

java -classpath /Users/admin/LOGS Insert_data

With the above I can run Insert_data from any directory on my machine, and I also have no trouble running/calling from cron.

Problem solved. Sorry to have gotten away from the main topic of discussion here, but I felt it might save others time, perhaps, to give a follow up.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Calling BASH script from JAVA

Hi, I am trying to call a bash script from a java file. Code to call bash script will look like: Runtime runtime = Runtime.getRuntime(); Process process = runtime.exec("mybashfile.sh"); It is succesfully calling the bash file. I am using simple rm commands in the script to remove... (0 Replies)
Discussion started by: lakshman.forums
0 Replies

2. Programming

calling java from c++

I have an adapter written in c++ from which I need to call a java service point. Could anybody please provide an example program of calling java from c++ thanks in advance. (0 Replies)
Discussion started by: axes
0 Replies

3. Shell Programming and Scripting

Calling Java Method from UNIX using shell script

Hi All, I need to call a java method from a shell script. I know we can use the command java ClassName to call the main method in it. But I need to call another method that is there in the class and pass an email to it. Can I use java ClassName.MethodName(email) Any help will be... (4 Replies)
Discussion started by: RahulK
4 Replies

4. Shell Programming and Scripting

Calling C program from cron results in no output

I can call a C program from the shell and results are outputted as normal. The C program processes some files and spits out a .csv file. If I scheduled it in cron, there is no output. If their a special way to schedule C programs in cron? thanks & regards (1 Reply)
Discussion started by: hazno
1 Replies

5. Shell Programming and Scripting

Issue calling scripts through CRON.

I have the following cron job in the crontab. #! /bin/bash 25 15 * * 1-5 /export/home/svittala/scripts/scpt1.sh >/dev/null 2>&1. The problem that I am facing is - the scpt1.sh can be executed manually. But, it is not executing through CRON. Not sure what's the issue. Any hints?. Thanks.... (5 Replies)
Discussion started by: vskr72
5 Replies

6. Solaris

Java errors

Solaris 10. Getting a boatload of "Resource unavailable" on read errors for a Java process which is taking 350% of CPU. No I/O issues and dtrace shows lots of lwp calls. There are only 54 threads (or so, it fluxuates) but certainly not a lot. App is WebLogic. App has been up since the third and... (2 Replies)
Discussion started by: BOFH
2 Replies

7. UNIX for Dummies Questions & Answers

Calling a PHP script from cron

This is a line from my crontab: 12 12 * * * /home/users/ElburdNDL/www/backups/adddate.php The permissions of the script is 755 it should execute ok....but it doesn't. Do I somehow have to give cron the path to PHP or something? If so, how exactly? Thanks. Ed PS Am a total newbie... (10 Replies)
Discussion started by: eludlow
10 Replies

8. UNIX for Dummies Questions & Answers

calling a script from java

HI I need to build a GUI where a button could execute a script in Solaris 8. I am working with Sun ONE Studio 7 Enterprice Edition. Thanks (1 Reply)
Discussion started by: javierelizabeth
1 Replies

9. UNIX for Dummies Questions & Answers

errors when running a cron job

I am running some shell scripts through a foll cron job, the script works fine and there are no errors in the log file but I receive the following error in mail for the jobs: stty: no such device or address What does the above error indicate, here is the cron job: 0 22 * * 0... (2 Replies)
Discussion started by: knarayan
2 Replies

10. UNIX for Dummies Questions & Answers

Java program calling a UNIX command

I was wondering if it was possible to call a unix command directly from a Java program during run-time. This command could very very basic e.g. "ps -ef" returned as a string, all I need is a starting place so if anyone has any suggestion or examples I would be very grateful (2 Replies)
Discussion started by: QUartz Ite
2 Replies
Login or Register to Ask a Question