• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

Question how to schedule a java command line?

sweetman

Basic Pleskian
Server operating system version
CentOS 7.9
Plesk version and microupdate number
Plesk Obsidian 18.0.44 update #3
Hello all,
I need to execute a JAVA command line at a specific time.
The command should use a file located on a specific folder.
Actually I run it manually by using the SSH Terminal and executing these operations:
1- change to the folder where the file to be run is located: cd /httpdocs/mydir
2- run the command line: java -jar myfile.jar myparameter configuration/myxmlfile.xml myparameter2
This work, manually.

But how can I schedule this command?
I'm pretty new to Plesk/Linux.

What is the best/simple option to schedule this on Plesk Obsidian?
JAVA JRE in already installed on the server, in case you ask.

Thanks you in advance.
Tony
 
Thanks for your reply, Igor.
I already read this article.
I tried to use the command: "java /var/www/vhosts/mydomain/httpdocs/connector/java test"
but it doesn't work. It breaks as soos as I run it with this error:
Task "java /var/www/vhosts/mydomain/httpdocs/connector/java test" completed with error in 0 seconds, output:
Error: Could not find or load main class .var.www.vhosts.mydomain.httpdocs.connector.java
Is there an alternative to run it?
THX again.
Tony

p.s.: I uploaded the tile test.class (compiled with jdk) on the same folder.
 
Thanks for your reply, Igor.
I already read this article.
I tried to use the command: "java /var/www/vhosts/mydomain/httpdocs/connector/java test"
but it doesn't work. It breaks as soos as I run it with this error:
Task "java /var/www/vhosts/mydomain/httpdocs/connector/java test" completed with error in 0 seconds, output:
Error: Could not find or load main class .var.www.vhosts.mydomain.httpdocs.connector.java
Is there an alternative to run it?
THX again.
Tony

p.s.: I uploaded the tile test.class (compiled with jdk) on the same folder.
I created a simple example command line: "java -version" and it works.
 
I created a simple example command line: "java -version" and it works.
Now I craeted a new script and it seems to work. But the script it's executing lots of operations.
When I run it manually it takes at least an hour.
If I run it now, plesk says that it has been executed in less than 5 seconds. Perhaps the script continue in the background? how can I check this?
TIA
tony
 
Are there any related errors in the logs while you execute the cronjob?

# tail -f /var/log/cron
 
what does the -f parameter mean? I can't find any reference of it online.
In any case the command is still executing and I can't see anythink abnormal (from my limited point of view, of course).
No reference to my script/command, for example.
tony
 
What exactly is the question? Are you worried the execution of your script goes too fast in the cronjob or too slow on the command line?
Does the script do what it's supposed to do?

Btw: there should be a mention of the user that executes the script in the cron log.
 
hi maartenv,
please consider that the scheduled process should take at least one hour and a half to complete (when you run it manually from SSH Terminal).
But when I click RUN NOW from the Plesk Task scheduler page I get the message that says "The task..... succesfully completed in 1 second". And nothing else happens.
So, my question is: is this task running in the background? how can I check this?
I can't see any reference to this process in the tail -f... command.
Thanks for your patience.
Tony
 
this is the command I would like to schedule:
java -jar /var/www/vhosts/mydomain/httpdocs/connector/Content.jar datasource /var/www/vhosts/mydomain/httpdocs/connector/configuration/Content.xml import
Do you see something wrong?
I modified the Plesk Task Scheduler settings to use the /bin/bash shell.
TIA
tony
 

Attachments

  • plesk schedule task.png
    plesk schedule task.png
    43.2 KB · Views: 7
What if you move the job to the subscription? You're running it as root right now.
Subscription -> Scheduled Tasks

You should see the user that executes it in the cron log.
 
What if you move the job to the subscription? You're running it as root right now.
Subscription -> Scheduled Tasks

You should see the user that executes it in the cron log.
I created a new task in the subscription, but nothing changed. I was not aware there was the task scheduler in the subscription. I discovered it by accident.
Tony
 
Instead of "java", use the real location, i.e. "/usr/bin/java"
Sorry for the stupid question: what if a task require 1 or 2 hours execution time? What should I see on screen in the plesk task scheduler page? a progress bar that start from 0 and go to 100 in 1 or 2 hours?
The command, when run from command line creates a log file itself, but every time I run the task in plesk scheduler, the log is not updated. So, I'm pretty confident that the task is not working. :(.
TIA
tony
 
I created a new task in the subscription, but nothing changed. I was not aware there was the task scheduler in the subscription. I discovered it by accident.
Tony
I forgot to mention that I changed the file path accordingly. So now the command is:
java -jar httpdocs/connector/Content.jar datasource httpdocs/connector/configuration/Content.xml import
But results are always the same, see attached image.
I'm now in a hurry to solve this problem, but have no idea where the problem is.
Tony
 

Attachments

  • task.png
    task.png
    21.9 KB · Views: 4
Sorry for the stupid question: what if a task require 1 or 2 hours execution time? What should I see on screen in the plesk task scheduler page? a progress bar that start from 0 and go to 100 in 1 or 2 hours?
Yes, it will update the popup in real-time.

I'm out of ideas, maybe someone else has a suggestion?

Otherwise, you could contact Plesk Support:

 
Back
Top