Solved

crontab problem

Posted on 2004-08-31
20
483 Views
Last Modified: 2013-12-27
Hi,

I have a shell script which I want to execute via a crontab every 2 minutes. I edited my crontab as follows:

bash-2.05$ crontab -e
2 * * * * /opt/vignette/V7/logs/dblogins.sh

But the above doesnt seem to do anything.  

Any suggestions as to whats wrong ?

thnx,

0
Comment
Question by:sgaucho
  • 8
  • 8
  • 2
  • +2
20 Comments
 
LVL 19

Expert Comment

by:ramazanyich
Comment Utility
you definiton is wrong. It should be:
2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58 * * * * /opt/vignette/V7/logs/dblogins.sh
0
 
LVL 19

Expert Comment

by:ramazanyich
Comment Utility
your original definition says that  script will  be executed on second minute of every hour
0
 

Author Comment

by:sgaucho
Comment Utility
Nope, its still not executing my script. can I debug this somehow ?

 Also, isnt the definition huge ? If i wanted to execute it every minute, it wud get even bigger.

thanks,
0
 
LVL 18

Expert Comment

by:liddler
Comment Utility
To do it every minute:
* * * * * /opt/vignette/V7/logs/dblogins.sh

Have a look in /var/cron/log and check your mail, cron messages should be mailed to you
0
 
LVL 4

Expert Comment

by:Otetelisanu
Comment Utility
You can make a script for every minute :

while true
do
sleep 60

Your_script
done

and you start as

nohup ./script &
0
 
LVL 19

Expert Comment

by:ramazanyich
Comment Utility
could you send the script ? Does it run from command line ?
0
 
LVL 4

Expert Comment

by:Otetelisanu
Comment Utility
1. you can from comand line run
Example:
while true
do
ls -l
sleep 60
done

2. you can from the script
     Example : my_script
  #
Envirnement variable

while true
do
ls -l >> /directory/file.log
sleep 60
done

and start as
nohup ./my_script &

0
 

Author Comment

by:sgaucho
Comment Utility
Hi,

pl tell me something. I have set the classpath in my env and also in my .profile. I can execute the script fine from command line and if I place a echo $CLASSPATH in the shell script, that too executes fine but when executing via the crontab, It reports an error saying :

Your "cron" job on wcmms01
/opt/vignette/V7/logs/dblogins.sh

produced the following output:

Exception in thread "main" java.lang.NoClassDefFoundError: com/oberon/runtime/ZipFileRuntime

I am quite sure this is a classpath problem. Any suggestions as to how I can resolve this??

thnx,
0
 
LVL 40

Expert Comment

by:jlevie
Comment Utility
A job running from cron will only have the basic system environment. It won't use your .profile so any env vars you set there won't be in effect. To fix this you'll need to add the setup for CLASSPATH to your script that you run from cron.
0
 

Author Comment

by:sgaucho
Comment Utility
Hi,

Ok, I edited my dblogins.sh as follows:

CLASSPATH=/opt/vignette/V7/vbis/lib/vbisclasses.jar:/usr/java:/usr/java/bin:/usr
/java/lib/tools.jar:/opt/vignette/V7/logs/ojdbc14.jar:/opt/vignette/V7/logs/LogD
b.jar
export CLASSPATH
LD_LIBRARY_PATH=/opt/vignette/V7/vbis/lib:
export LD_LIBRARY_PATH

echo $CLASSPATH

echo $LD_LIBRARY_PATH

java com.oberon.runtime.ZipFileRuntime LogDb.jar  -fname /opt/vignette/V7/logs/W
CM_export_19760817.csv


ANd the output I am getting now from the CRON is :

Your "cron" job on wcmms01
/opt/vignette/V7/logs/dblogins.sh

produced the following output:

/opt/vignette/V7/vbis/lib/vbisclasses.jar:/usr/java:/usr/java/bin:/usr/java/lib/tools.jar:/opt/vignette/V7/logs/ojdbc14.jar:/opt/vignette/V7/logs/LogDb.jar
/opt/vignette/V7/vbis/lib:
java.util.zip.ZipException: No such file or directory
        at java.util.zip.ZipFile.open(Native Method)
        at java.util.zip.ZipFile.<init>(ZipFile.java:112)
        at java.util.zip.ZipFile.<init>(ZipFile.java:72)
        at com.oberon.runtime.ZipFileApplicationSource.<init>(Unknown Source)
        at com.oberon.runtime.ZipFileRuntime.main(Unknown Source)

Why am I getting this error ?

TIA
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:sgaucho
Comment Utility
Hi again,

The while loop works fine except on the production server I need the script to run every day at 10 minutes to midnight (1150 pm everyday). Would it be feasible and advisable to do this within the script ? wudnt it be better to execute the script via a crontab ?

thnx
0
 
LVL 19

Accepted Solution

by:
ramazanyich earned 100 total points
Comment Utility
provide full path to LogDb.jar  file
0
 

Author Comment

by:sgaucho
Comment Utility
I have provided the full path to LogDb.jar  in my classpath
0
 
LVL 19

Expert Comment

by:ramazanyich
Comment Utility
But why do you use it as parameter for your class ???
0
 
LVL 19

Expert Comment

by:ramazanyich
Comment Utility
java com.oberon.runtime.ZipFileRuntime LogDb.jar  -fname /opt/vignette/V7/logs/WCM_export_19760817.csv

It means that args[0] for ZipFileRuntime will be LogDb.jar
0
 

Author Comment

by:sgaucho
Comment Utility
The class is part of an application compiled by another software and which requires a parameter to be supplied dynamically at runtime.

The command java com.oberon.runtime.ZipFileRuntime LogDb.jar  -fname /opt/vignette/V7/logs/WCM_export_19760817.csv works just fine when executed at the command line or via a shell script. Its only when I try to execute the script via a crontab that the problems start.
0
 
LVL 19

Expert Comment

by:ramazanyich
Comment Utility
Probably your class reads that file then it is provided as parameter, that's why you should try to provide full pathname to that jar file. Just try it. Hope that will help.
0
 

Author Comment

by:sgaucho
Comment Utility
ramazanyich, You were right! thnx a bunch..

Just one last question before I close this issue. I need the crontab to execute the script everyday at 2340 hours or 20 minutes to midnight.

thnx
0
 
LVL 19

Expert Comment

by:ramazanyich
Comment Utility
40 23 * * * /opt/vignette/V7/logs/dblogins.sh
0
 

Author Comment

by:sgaucho
Comment Utility
Thnx a bunch. :)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now