LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-19-2004, 06:16 AM   #1
pcdude
LQ Newbie
 
Registered: Sep 2004
Location: South Africa
Distribution: Mandrake
Posts: 26

Rep: Reputation: 15
Calling Ant buildfile from cron


HI all.

I hope that this is the right forum for my question.

I'm using mandrake 9.2 and trying to implement nightly builds on my Java Project. I using ANT to do this. I want to setup CRON to do this.
Problem is the the environment variables for ant are not setup when CRON calls ANT, so I must set up these in the script.

Am I correct so far?

The Script that I am calling looks like this:
Code:
export $PATH=$PATH:/usr/local/apache-ant-1.6.2
echo "New path is: " >> /tmp/debug.txt
echo $PATH >> /tmp/debug.txt
export $ANT_HOME=/usr/local/apache-ant-1.6.2
echo "Ant_Home:" >> /tmp/debug.txt
echo $ANT_HOME >> /tmp/debug.txt
ant -buildfile /home/user/tempBuild/build.xml
I used debug.txt to see if the environment variables have changed, and they did not. My Ant script is never run so I assume this is the problem.

What am I doing wrong?

Any advice would be appreciated.
Thanks in advance.
 
Old 10-19-2004, 06:22 AM   #2
Hcman
Member
 
Registered: Jan 2003
Location: Holland
Distribution: OpenBSD 3.6 - Arch Linux 0.7
Posts: 210

Rep: Reputation: 30
Did you edit your crontab <crontab -e>?
You can check the current cron jobs in a users crontab with <crontab -l>

Arjan
 
Old 10-19-2004, 06:54 AM   #3
pcdude
LQ Newbie
 
Registered: Sep 2004
Location: South Africa
Distribution: Mandrake
Posts: 26

Original Poster
Rep: Reputation: 15
I edited /etc/crontab directly. Is this wrong?
The build must must be called even if I am not logged in, so I adding the entry to the root's cron table
 
Old 10-19-2004, 07:26 AM   #4
Hcman
Member
 
Registered: Jan 2003
Location: Holland
Distribution: OpenBSD 3.6 - Arch Linux 0.7
Posts: 210

Rep: Reputation: 30
You can:

1) put your script in /etc/cron.daily and it will be run (surprise) daily.
2) edit your users crontab <crontab -e> (don't edit directly I have always been told) and it will run even if you are not logged in.
Put a line in like this "30 23 * * * <path to your script>" and it will be run every day at 11:30pm.

I'd opt for the second since there is no reason to run your script as root (or is there?).

Arjan
 
Old 10-19-2004, 09:07 AM   #5
pcdude
LQ Newbie
 
Registered: Sep 2004
Location: South Africa
Distribution: Mandrake
Posts: 26

Original Poster
Rep: Reputation: 15
I've taken your advice and added the command using crontab -e
It seems I'm now back at square one.
If I put the Ant command in crontab ( using crontab -e), ANT does not execute because it says that it requires the JAVA_HOME environment variable to be set.
I then went and made a script file that sets the environment variables similar to my orignal post and set crontab to run this.
Nothing happens and I don't know how to debug it since I can't get any output ( > error.txt on the end of the cron command does not work with the script file).

Any additional advice would be appreciated.
 
Old 10-19-2004, 09:53 AM   #6
Hcman
Member
 
Registered: Jan 2003
Location: Holland
Distribution: OpenBSD 3.6 - Arch Linux 0.7
Posts: 210

Rep: Reputation: 30
Is your script executable?
<chmod +x yourscript>

It works when you try to run it normally right?

Arjan
 
Old 10-19-2004, 10:02 AM   #7
pcdude
LQ Newbie
 
Registered: Sep 2004
Location: South Africa
Distribution: Mandrake
Posts: 26

Original Poster
Rep: Reputation: 15
Yes, my script is executable and it works when I call it from the commad line.
 
Old 10-19-2004, 05:43 PM   #8
Hcman
Member
 
Registered: Jan 2003
Location: Holland
Distribution: OpenBSD 3.6 - Arch Linux 0.7
Posts: 210

Rep: Reputation: 30
Well then I dunno. Post your exact script and your crontab. Perhaps it's just a typo you have overlooked eh?

Arjan
 
Old 10-20-2004, 04:36 AM   #9
pcdude
LQ Newbie
 
Registered: Sep 2004
Location: South Africa
Distribution: Mandrake
Posts: 26

Original Poster
Rep: Reputation: 15
Oops

I was setting my environment variables in the scripts like
Code:
export $PATH=$PATH:/newpath
instead of
Code:
export PATH=$PATH:/newpath
Anyways it works now, thanks for your help!
 
Old 10-20-2004, 05:11 AM   #10
Hcman
Member
 
Registered: Jan 2003
Location: Holland
Distribution: OpenBSD 3.6 - Arch Linux 0.7
Posts: 210

Rep: Reputation: 30
I didn't even notice that sheesh!
Glad you got it to work.
 
  


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
Problems about ant simprince Programming 1 11-08-2005 09:53 AM
problem with ant os2 Programming 1 05-20-2005 12:13 AM
odd recursion: calling "by hand" vs calling by cronscript... prx Programming 4 02-12-2005 04:59 PM
Calling a Php file from CRON every hours ? airbuzz *BSD 10 02-03-2004 02:04 PM
Jakarta Ant?? powadha Linux - Software 3 01-19-2004 12:46 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:12 PM.

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