Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

crontab problem

Posted on 2004-08-31
20
Medium Priority
?
494 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 8
  • 2
  • +2
20 Comments
 
LVL 19

Expert Comment

by:ramazanyich
ID: 11940349
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
ID: 11940355
your original definition says that  script will  be executed on second minute of every hour
0
 

Author Comment

by:sgaucho
ID: 11940421
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 18

Expert Comment

by:liddler
ID: 11940586
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
ID: 11940599
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
ID: 11940641
could you send the script ? Does it run from command line ?
0
 
LVL 4

Expert Comment

by:Otetelisanu
ID: 11941542
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
ID: 11942107
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
ID: 11942163
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
ID: 11942564
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
 

Author Comment

by:sgaucho
ID: 11942849
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 400 total points
ID: 11943683
provide full path to LogDb.jar  file
0
 

Author Comment

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

Expert Comment

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

Expert Comment

by:ramazanyich
ID: 11944224
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
ID: 11944575
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
ID: 11944633
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
ID: 11952991
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
ID: 11953035
40 23 * * * /opt/vignette/V7/logs/dblogins.sh
0
 

Author Comment

by:sgaucho
ID: 11953198
Thnx a bunch. :)
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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.:

618 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