Cron tab to run a java file
I'm having issues getting a cron tab to run a java file every 5 minutes.
I have tried to create an executable script to see if that is what's needed:
My script and java file are both stored in /usr/local/bin
and this is what I have in my crontab:
*/5 * * * * /usr/local/bin/java-crontab.sh
This is what I have in my script
#!/bin/bash
JAVA_HOME=usr/java/jdk1.6.0_40
export JAVA_HOME
PATH=$JAVA_HOME/bin:$PATH
export PATH
java -jar /usr/local/bin/javatest.jar
scripting cron java
bumped to the homepage by Community♦ 11 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
I'm having issues getting a cron tab to run a java file every 5 minutes.
I have tried to create an executable script to see if that is what's needed:
My script and java file are both stored in /usr/local/bin
and this is what I have in my crontab:
*/5 * * * * /usr/local/bin/java-crontab.sh
This is what I have in my script
#!/bin/bash
JAVA_HOME=usr/java/jdk1.6.0_40
export JAVA_HOME
PATH=$JAVA_HOME/bin:$PATH
export PATH
java -jar /usr/local/bin/javatest.jar
scripting cron java
bumped to the homepage by Community♦ 11 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
Welcome to Unix Stackexchange! You can take the tour first and the learn How to Ask a good question. That makes it easier for us to help you.
– andcoz
Feb 6 '17 at 13:40
@hannah-s check the mailbox of the user that owns the crontab for error log emails,
– andcoz
Feb 6 '17 at 13:43
Do you think you have to define JAVA_HOME each time you run a java app? You don't have to. Just use the absolute path to java: /usr/share/doc/openjdk-6-jre-headless/java -jar ...
– ka3ak
Feb 6 '17 at 16:06
Ahhh i didn't know - it still isn't working I'm afraid unless i still have a typo, iv changed the script file to: #!/bin/bash export PATH=/usr/share/doc/openjdk-6-jre-headless:$PATH java -jar /usr/local/bin/javatest.jar but it isn't running :(
– Hannah.S
Feb 6 '17 at 16:25
add a comment |
I'm having issues getting a cron tab to run a java file every 5 minutes.
I have tried to create an executable script to see if that is what's needed:
My script and java file are both stored in /usr/local/bin
and this is what I have in my crontab:
*/5 * * * * /usr/local/bin/java-crontab.sh
This is what I have in my script
#!/bin/bash
JAVA_HOME=usr/java/jdk1.6.0_40
export JAVA_HOME
PATH=$JAVA_HOME/bin:$PATH
export PATH
java -jar /usr/local/bin/javatest.jar
scripting cron java
I'm having issues getting a cron tab to run a java file every 5 minutes.
I have tried to create an executable script to see if that is what's needed:
My script and java file are both stored in /usr/local/bin
and this is what I have in my crontab:
*/5 * * * * /usr/local/bin/java-crontab.sh
This is what I have in my script
#!/bin/bash
JAVA_HOME=usr/java/jdk1.6.0_40
export JAVA_HOME
PATH=$JAVA_HOME/bin:$PATH
export PATH
java -jar /usr/local/bin/javatest.jar
scripting cron java
scripting cron java
edited Nov 18 '18 at 6:28
Rui F Ribeiro
40.7k1479137
40.7k1479137
asked Feb 6 '17 at 13:31
Hannah.SHannah.S
11
11
bumped to the homepage by Community♦ 11 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
bumped to the homepage by Community♦ 11 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
Welcome to Unix Stackexchange! You can take the tour first and the learn How to Ask a good question. That makes it easier for us to help you.
– andcoz
Feb 6 '17 at 13:40
@hannah-s check the mailbox of the user that owns the crontab for error log emails,
– andcoz
Feb 6 '17 at 13:43
Do you think you have to define JAVA_HOME each time you run a java app? You don't have to. Just use the absolute path to java: /usr/share/doc/openjdk-6-jre-headless/java -jar ...
– ka3ak
Feb 6 '17 at 16:06
Ahhh i didn't know - it still isn't working I'm afraid unless i still have a typo, iv changed the script file to: #!/bin/bash export PATH=/usr/share/doc/openjdk-6-jre-headless:$PATH java -jar /usr/local/bin/javatest.jar but it isn't running :(
– Hannah.S
Feb 6 '17 at 16:25
add a comment |
Welcome to Unix Stackexchange! You can take the tour first and the learn How to Ask a good question. That makes it easier for us to help you.
– andcoz
Feb 6 '17 at 13:40
@hannah-s check the mailbox of the user that owns the crontab for error log emails,
– andcoz
Feb 6 '17 at 13:43
Do you think you have to define JAVA_HOME each time you run a java app? You don't have to. Just use the absolute path to java: /usr/share/doc/openjdk-6-jre-headless/java -jar ...
– ka3ak
Feb 6 '17 at 16:06
Ahhh i didn't know - it still isn't working I'm afraid unless i still have a typo, iv changed the script file to: #!/bin/bash export PATH=/usr/share/doc/openjdk-6-jre-headless:$PATH java -jar /usr/local/bin/javatest.jar but it isn't running :(
– Hannah.S
Feb 6 '17 at 16:25
Welcome to Unix Stackexchange! You can take the tour first and the learn How to Ask a good question. That makes it easier for us to help you.
– andcoz
Feb 6 '17 at 13:40
Welcome to Unix Stackexchange! You can take the tour first and the learn How to Ask a good question. That makes it easier for us to help you.
– andcoz
Feb 6 '17 at 13:40
@hannah-s check the mailbox of the user that owns the crontab for error log emails,
– andcoz
Feb 6 '17 at 13:43
@hannah-s check the mailbox of the user that owns the crontab for error log emails,
– andcoz
Feb 6 '17 at 13:43
Do you think you have to define JAVA_HOME each time you run a java app? You don't have to. Just use the absolute path to java: /usr/share/doc/openjdk-6-jre-headless/java -jar ...
– ka3ak
Feb 6 '17 at 16:06
Do you think you have to define JAVA_HOME each time you run a java app? You don't have to. Just use the absolute path to java: /usr/share/doc/openjdk-6-jre-headless/java -jar ...
– ka3ak
Feb 6 '17 at 16:06
Ahhh i didn't know - it still isn't working I'm afraid unless i still have a typo, iv changed the script file to: #!/bin/bash export PATH=/usr/share/doc/openjdk-6-jre-headless:$PATH java -jar /usr/local/bin/javatest.jar but it isn't running :(
– Hannah.S
Feb 6 '17 at 16:25
Ahhh i didn't know - it still isn't working I'm afraid unless i still have a typo, iv changed the script file to: #!/bin/bash export PATH=/usr/share/doc/openjdk-6-jre-headless:$PATH java -jar /usr/local/bin/javatest.jar but it isn't running :(
– Hannah.S
Feb 6 '17 at 16:25
add a comment |
2 Answers
2
active
oldest
votes
your java-crontab.sh
has a typo. JAVA_HOME
should be an absolute path.
Simplifying, you could go with
#!/bin/sh
export PATH=/usr/java/jdk1.6.0_40:$PATH
java -jar /usr/local/bin/javatest.jar
I've just realised that JAVA_HOME is set in /usr/lib/jvm/java-6-sun. If I give rwx permissions and place that in my script should that theoretically work?
– Hannah.S
Feb 6 '17 at 14:10
In theory. Don't forget to replace/usr/java/jdk1.6.0_40
with/usr/lib/jvm/java-6-sun
. Try running the script manually before configuring your crontab. If it fails, tell us what's going on, ...
– SYN
Feb 7 '17 at 5:51
Hello, so I ran the script using the bash command and I got an error saying 'exception in thread "main" java.lang.reflect.inovocationtargetexception etc etc
– Hannah.S
Feb 7 '17 at 17:56
without the full trace and some visual on your sources, there's no way of telling what happened. Regardless, my first guess would be you're running an old version of Java: are you sure this jar is supposed to work with 1.6?
– SYN
Feb 7 '17 at 18:08
The sys log file just says 'NO MTA installed, discarding output' I did install postfix but the crontab still was not running the jar file so I returned to my earlier snapshot which was before I installed postfix. I also created a new logfile in hope the crontab would report the errors into that but the logfile remained blank
– Hannah.S
Feb 8 '17 at 17:31
|
show 1 more comment
Sorry update - my JAVA_HOME file is not stored in usr/java but in usr/share/doc/openjdk-6-jre-headless. However when I enter that path in the executable script file I don't have permission to do so.
Brand new to creating VM's so apologies for my utter confusion here!
Since you're new here: you should edit your initial post, instead of proposing answers correcting your question.
– SYN
Feb 7 '17 at 5:48
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f342871%2fcron-tab-to-run-a-java-file%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
your java-crontab.sh
has a typo. JAVA_HOME
should be an absolute path.
Simplifying, you could go with
#!/bin/sh
export PATH=/usr/java/jdk1.6.0_40:$PATH
java -jar /usr/local/bin/javatest.jar
I've just realised that JAVA_HOME is set in /usr/lib/jvm/java-6-sun. If I give rwx permissions and place that in my script should that theoretically work?
– Hannah.S
Feb 6 '17 at 14:10
In theory. Don't forget to replace/usr/java/jdk1.6.0_40
with/usr/lib/jvm/java-6-sun
. Try running the script manually before configuring your crontab. If it fails, tell us what's going on, ...
– SYN
Feb 7 '17 at 5:51
Hello, so I ran the script using the bash command and I got an error saying 'exception in thread "main" java.lang.reflect.inovocationtargetexception etc etc
– Hannah.S
Feb 7 '17 at 17:56
without the full trace and some visual on your sources, there's no way of telling what happened. Regardless, my first guess would be you're running an old version of Java: are you sure this jar is supposed to work with 1.6?
– SYN
Feb 7 '17 at 18:08
The sys log file just says 'NO MTA installed, discarding output' I did install postfix but the crontab still was not running the jar file so I returned to my earlier snapshot which was before I installed postfix. I also created a new logfile in hope the crontab would report the errors into that but the logfile remained blank
– Hannah.S
Feb 8 '17 at 17:31
|
show 1 more comment
your java-crontab.sh
has a typo. JAVA_HOME
should be an absolute path.
Simplifying, you could go with
#!/bin/sh
export PATH=/usr/java/jdk1.6.0_40:$PATH
java -jar /usr/local/bin/javatest.jar
I've just realised that JAVA_HOME is set in /usr/lib/jvm/java-6-sun. If I give rwx permissions and place that in my script should that theoretically work?
– Hannah.S
Feb 6 '17 at 14:10
In theory. Don't forget to replace/usr/java/jdk1.6.0_40
with/usr/lib/jvm/java-6-sun
. Try running the script manually before configuring your crontab. If it fails, tell us what's going on, ...
– SYN
Feb 7 '17 at 5:51
Hello, so I ran the script using the bash command and I got an error saying 'exception in thread "main" java.lang.reflect.inovocationtargetexception etc etc
– Hannah.S
Feb 7 '17 at 17:56
without the full trace and some visual on your sources, there's no way of telling what happened. Regardless, my first guess would be you're running an old version of Java: are you sure this jar is supposed to work with 1.6?
– SYN
Feb 7 '17 at 18:08
The sys log file just says 'NO MTA installed, discarding output' I did install postfix but the crontab still was not running the jar file so I returned to my earlier snapshot which was before I installed postfix. I also created a new logfile in hope the crontab would report the errors into that but the logfile remained blank
– Hannah.S
Feb 8 '17 at 17:31
|
show 1 more comment
your java-crontab.sh
has a typo. JAVA_HOME
should be an absolute path.
Simplifying, you could go with
#!/bin/sh
export PATH=/usr/java/jdk1.6.0_40:$PATH
java -jar /usr/local/bin/javatest.jar
your java-crontab.sh
has a typo. JAVA_HOME
should be an absolute path.
Simplifying, you could go with
#!/bin/sh
export PATH=/usr/java/jdk1.6.0_40:$PATH
java -jar /usr/local/bin/javatest.jar
answered Feb 6 '17 at 13:50
SYNSYN
1,899515
1,899515
I've just realised that JAVA_HOME is set in /usr/lib/jvm/java-6-sun. If I give rwx permissions and place that in my script should that theoretically work?
– Hannah.S
Feb 6 '17 at 14:10
In theory. Don't forget to replace/usr/java/jdk1.6.0_40
with/usr/lib/jvm/java-6-sun
. Try running the script manually before configuring your crontab. If it fails, tell us what's going on, ...
– SYN
Feb 7 '17 at 5:51
Hello, so I ran the script using the bash command and I got an error saying 'exception in thread "main" java.lang.reflect.inovocationtargetexception etc etc
– Hannah.S
Feb 7 '17 at 17:56
without the full trace and some visual on your sources, there's no way of telling what happened. Regardless, my first guess would be you're running an old version of Java: are you sure this jar is supposed to work with 1.6?
– SYN
Feb 7 '17 at 18:08
The sys log file just says 'NO MTA installed, discarding output' I did install postfix but the crontab still was not running the jar file so I returned to my earlier snapshot which was before I installed postfix. I also created a new logfile in hope the crontab would report the errors into that but the logfile remained blank
– Hannah.S
Feb 8 '17 at 17:31
|
show 1 more comment
I've just realised that JAVA_HOME is set in /usr/lib/jvm/java-6-sun. If I give rwx permissions and place that in my script should that theoretically work?
– Hannah.S
Feb 6 '17 at 14:10
In theory. Don't forget to replace/usr/java/jdk1.6.0_40
with/usr/lib/jvm/java-6-sun
. Try running the script manually before configuring your crontab. If it fails, tell us what's going on, ...
– SYN
Feb 7 '17 at 5:51
Hello, so I ran the script using the bash command and I got an error saying 'exception in thread "main" java.lang.reflect.inovocationtargetexception etc etc
– Hannah.S
Feb 7 '17 at 17:56
without the full trace and some visual on your sources, there's no way of telling what happened. Regardless, my first guess would be you're running an old version of Java: are you sure this jar is supposed to work with 1.6?
– SYN
Feb 7 '17 at 18:08
The sys log file just says 'NO MTA installed, discarding output' I did install postfix but the crontab still was not running the jar file so I returned to my earlier snapshot which was before I installed postfix. I also created a new logfile in hope the crontab would report the errors into that but the logfile remained blank
– Hannah.S
Feb 8 '17 at 17:31
I've just realised that JAVA_HOME is set in /usr/lib/jvm/java-6-sun. If I give rwx permissions and place that in my script should that theoretically work?
– Hannah.S
Feb 6 '17 at 14:10
I've just realised that JAVA_HOME is set in /usr/lib/jvm/java-6-sun. If I give rwx permissions and place that in my script should that theoretically work?
– Hannah.S
Feb 6 '17 at 14:10
In theory. Don't forget to replace
/usr/java/jdk1.6.0_40
with /usr/lib/jvm/java-6-sun
. Try running the script manually before configuring your crontab. If it fails, tell us what's going on, ...– SYN
Feb 7 '17 at 5:51
In theory. Don't forget to replace
/usr/java/jdk1.6.0_40
with /usr/lib/jvm/java-6-sun
. Try running the script manually before configuring your crontab. If it fails, tell us what's going on, ...– SYN
Feb 7 '17 at 5:51
Hello, so I ran the script using the bash command and I got an error saying 'exception in thread "main" java.lang.reflect.inovocationtargetexception etc etc
– Hannah.S
Feb 7 '17 at 17:56
Hello, so I ran the script using the bash command and I got an error saying 'exception in thread "main" java.lang.reflect.inovocationtargetexception etc etc
– Hannah.S
Feb 7 '17 at 17:56
without the full trace and some visual on your sources, there's no way of telling what happened. Regardless, my first guess would be you're running an old version of Java: are you sure this jar is supposed to work with 1.6?
– SYN
Feb 7 '17 at 18:08
without the full trace and some visual on your sources, there's no way of telling what happened. Regardless, my first guess would be you're running an old version of Java: are you sure this jar is supposed to work with 1.6?
– SYN
Feb 7 '17 at 18:08
The sys log file just says 'NO MTA installed, discarding output' I did install postfix but the crontab still was not running the jar file so I returned to my earlier snapshot which was before I installed postfix. I also created a new logfile in hope the crontab would report the errors into that but the logfile remained blank
– Hannah.S
Feb 8 '17 at 17:31
The sys log file just says 'NO MTA installed, discarding output' I did install postfix but the crontab still was not running the jar file so I returned to my earlier snapshot which was before I installed postfix. I also created a new logfile in hope the crontab would report the errors into that but the logfile remained blank
– Hannah.S
Feb 8 '17 at 17:31
|
show 1 more comment
Sorry update - my JAVA_HOME file is not stored in usr/java but in usr/share/doc/openjdk-6-jre-headless. However when I enter that path in the executable script file I don't have permission to do so.
Brand new to creating VM's so apologies for my utter confusion here!
Since you're new here: you should edit your initial post, instead of proposing answers correcting your question.
– SYN
Feb 7 '17 at 5:48
add a comment |
Sorry update - my JAVA_HOME file is not stored in usr/java but in usr/share/doc/openjdk-6-jre-headless. However when I enter that path in the executable script file I don't have permission to do so.
Brand new to creating VM's so apologies for my utter confusion here!
Since you're new here: you should edit your initial post, instead of proposing answers correcting your question.
– SYN
Feb 7 '17 at 5:48
add a comment |
Sorry update - my JAVA_HOME file is not stored in usr/java but in usr/share/doc/openjdk-6-jre-headless. However when I enter that path in the executable script file I don't have permission to do so.
Brand new to creating VM's so apologies for my utter confusion here!
Sorry update - my JAVA_HOME file is not stored in usr/java but in usr/share/doc/openjdk-6-jre-headless. However when I enter that path in the executable script file I don't have permission to do so.
Brand new to creating VM's so apologies for my utter confusion here!
answered Feb 6 '17 at 14:14
Hannah.SHannah.S
11
11
Since you're new here: you should edit your initial post, instead of proposing answers correcting your question.
– SYN
Feb 7 '17 at 5:48
add a comment |
Since you're new here: you should edit your initial post, instead of proposing answers correcting your question.
– SYN
Feb 7 '17 at 5:48
Since you're new here: you should edit your initial post, instead of proposing answers correcting your question.
– SYN
Feb 7 '17 at 5:48
Since you're new here: you should edit your initial post, instead of proposing answers correcting your question.
– SYN
Feb 7 '17 at 5:48
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f342871%2fcron-tab-to-run-a-java-file%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Welcome to Unix Stackexchange! You can take the tour first and the learn How to Ask a good question. That makes it easier for us to help you.
– andcoz
Feb 6 '17 at 13:40
@hannah-s check the mailbox of the user that owns the crontab for error log emails,
– andcoz
Feb 6 '17 at 13:43
Do you think you have to define JAVA_HOME each time you run a java app? You don't have to. Just use the absolute path to java: /usr/share/doc/openjdk-6-jre-headless/java -jar ...
– ka3ak
Feb 6 '17 at 16:06
Ahhh i didn't know - it still isn't working I'm afraid unless i still have a typo, iv changed the script file to: #!/bin/bash export PATH=/usr/share/doc/openjdk-6-jre-headless:$PATH java -jar /usr/local/bin/javatest.jar but it isn't running :(
– Hannah.S
Feb 6 '17 at 16:25