Solved

crontab problem

Posted on 2004-08-31
20
489 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
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
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
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 100 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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

My previous tech tip, Installing the Solaris OS From the Flash Archive On a Tape (http://www.experts-exchange.com/articles/OS/Unix/Solaris/Installing-the-Solaris-OS-From-the-Flash-Archive-on-a-Tape.html), discussed installing the Solaris Operating S…
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
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.:
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

823 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