CronJob Runs but Does Not generate output - java

I have a shell script which executes a java class and it is supposed to run weekly using Cronjob.
Last few days it hasn't been working as expected.
It does not generate any kind of logs or output.
checked /var/logs ,the cronjob looks like it is running on the time it has been scheduled to.
Also , if i manually run/execute the java class it works perfectly fine.
Any idea why cron isn't working?
PS: A similar shell script scheduled at a different time running the same java class is working without a problem.

Your question is if we have any ideas why cron isn't working. Based on what you wrote, I think that you probably recently moved the input or output file. It may run when you execute it manually but cron runs from a different location, so you have to use full paths to all files and commands, please try this. Source: Experienced same problem
Best Regards

Related

Launch program from batch file generated by Java

I made a way to make my program, written in Java, update itself. The final JAR is wrapped in a EXE file, through Launch4j tool.
You need to know this piece of code:
System.getProperty("java.class.path").replaceAll("\\;\\.$", "")
gives me the actual path of the EXE. I tested it and it seems to be always working. This is important for the problem.
Now, basically the program pings a webpage and reads a series of values, which one of them is the latest version of the program. If it's greater, the program notifies the user for the update. So, the program downloads the remote data (updated EXE file) and stores them in the current running EXE file, whose filename is obtained through the method explained above. It works, but here comes the problem.
I could simply launch the downloaded EXE file and System.exit the current one, but I cannot do this, because my program works with smart cards: if two or more programs use the same smart cards, the new one won't work (I don't know why, I even restart the provider each time, but this is another story). So I prevent users from starting multiple istances of the program.
(My customers are not so smart to manually open the program each time they need it, so I needed to override the close button to make it stay in traybar, and wake up everytime it is needed. I even make it starts when Windows boots up).
So I have to close the current instance of the program, and launch again.
How I do this? I write a batch file which will basically look like this:
#echo off
taskkill /f /pid <pid of the exe program>
ping 127.0.0.1 -n 3 (this is a way to wait. I will eventually lower the waiting)
C:\Users\Mark\Desktop\program.exe (string generated by the method above. It should launch the program)
exit
Once written to disk, I execute it through Java:
Runtime.getRuntime().exec("cmd /c start " + batchFile.toString());
"batchFile" variable is a File object.
The problem is that the new downloaded program is not launched. A console window appears, shows the result of "taskkill" and "ping" (I will eventually mute them), but the program does not start. If I launch the batch file manually, it does.
Why? I really don't understand this behaviour.
Do you have any advice?
Thanks in advance!
TL;DR version:
The batch file executed by my Java program does not start the exe file written in it. Why?
I have the feeling you are trying to overwrite an executable file (EXE) that is currently running. AFAIK Windows locks such files and thus your updates should never happen.
To resolve your problem: I would split your application in two.
One part ensures the other part has the latest version, then executes that latest version.
For Java, something like this has been developed many years ago as WebStart technology, was marked as deprecated for Java 9 and removed thereafter. Meanwhile there is the project https://openwebstart.com/ that you might want to check out.

Can Symfony run Java jobs over Beanstalk?

I'm working on a Symfony 3 (PHP) project.
I would like to launch a Java executable using parameters I got from Symfony.
Some informations to consider:
The executable generates a file as an output.
Execution can take several minutes depending on the input parameters.
Multiple users can trigger the execution simultaneously.
I'm looking for a long-term sustainable solution. Do you have any advice?
After some research on queues.io, I found out that Beanstalk for PHP seems to be fitting my needs, but I would like to confirm or infirm this position with you.
What would you do in a similar case?

java - how reflect a long running workflow process in GUI?

I have a workflow of functions that eventually lead to a deployment of something.
the steps are as followed:
run a python script the produces some output.
run a bash script that copies this output to a given location
run a bash script (depending on the output of 1,2) that runs a java program (running make take few hours)
run another bash script on this output - final step
i want to be able to initiate this workflow from a GUI giving a set of parameters.
Then, I want to be able to get status reports of each step - so that the running user will know which step is currently running.
The main issue here is that each of the steps may take long time to finish.
My experience with developing GUI in java is limited.
Any advice on the direction I should go to?
If you really want to write this in Java, then you should try to find a good wizard library. See this question for some details.
Then, if at all possible that your scripts provide some feedback like the percentage of the operation completed then you could have a JProgressBar for each step independently and an overall one to show the user an idea of how much is done at any moment.

Java program running in background

I have a simple java program which is just a single piece of code that reads from a database and modifies the contents of the database based on certain conditions. Now, what I want is that this program should start automatically at the startup and silently run in the background unless someone kills it from the task manager.
I have never done something like this before and don't know exactly how to go about it. Can someone help me out as to how this can be done?
Thank you..
Follow the these steps to do the job :(Assuming you are using windows and jre is installed )
First compile your java program and place the class file at one location.
Now create a bat file and place java LOCATION TO THAT CLASS FILE/MyProgram in that.
Put your bat file in start up programs
Restart the system, you will get your program running in back ground..!
Hope this will help you.
There are two problems here
How to add this program to the startup
Windows - Run Java application at Windows startup
Linux - Linux start-up script for java application
Run the program as a daemon (background process)
Simplest way to do is using a while loop and sleep for required time interval in the while loop. Then perform the database
operation.
Also for windows, you can check this JSL
http://www.roeschter.com/
Thanks.
first create you jar bash and then add it to you crontab task list.

schedule java program

I want to run my java program in regular interval , lets say, in every 3 hours. I am thinking to write a .bat file and put command to call java class. But what is the best way to run .bat regularly in windows xp. Thanks in advance. I dont want to use third party tool.
Windows scheduled tasks are built for exactly that purpose.
You can run things on multiple schedules (so you can get your every-three-hour behaviour) and you can get your code to run whether or not logged in.
The multiple scheduling is a bit tricky. You basically set it up as a daily task to start with but, near the end, it will ask you if you want to do advanced features.
Select yes then you can set up multiple schedules at that point.
If you want a pure Java Based solution you can try QUARTZ SCHEDULER. But as paxdiablo already mentioned, Windows Task Scheduler will do that as well.

Categories