3

I am encountering a problem that I think there is a simple solution for. I'm currently using WinSCP (set up for FTP) with a Linux server for hosting a web application.

I've created a JAR file (filename.jar) that I can run manually in the WinSCP Console (java -jar filename.jar). It runs queries in a MySQL database that modifies an existing table. Effectively, for my front-end (that queries from this table) to be updated, it needs to have filename.jar file run twice daily.

I am wondering what the proper way to approach this is. Ideally, it would be done at 00:05 and 12:05 each day. If WinSCP can be configured to run filename.jar specifically at these times, that would be perfect. However, if there's a way to run the .jar continuously, I figure a while-loop verifying the desired system time within filename.jar would work as well.

I've seen lots of information on doing this locally, but found little to nothing helpful on doing this for a server. Thanks for any help or ideas in advance, let me know if I can improve this question or provide more information. If there are any resources that explain this clearly a link to those would be greatly appreciated as well. I'm a new WinSCP user, if you can't tell already.

Community
  • 1
  • 1
JamesR
  • 67
  • 2
  • 8
  • how about copying the jar to the linux server and creating a cron job for it? or is it not possible? – gybandi Jul 06 '16 at 08:59
  • Maybe another way would be to use openssh to connect to the server, the command line of the ssh program allows to give the remote commands. Also might be possible with plink from putty – Stefan Hegny Jul 06 '16 at 15:18
  • 1
    @gybandi This seems to work. I found a good resource [here](http://www.thesitewizard.com/general/set-cron-job.shtml). Do you have any idea how to check to make sure it is running? I already used the command `crontab -l` in the Console but it just shows me the schedule: `4 12 * * * /usr/local/new_promo.jar`. Is this enough of a confirmation it will be working on the server? – JamesR Jul 07 '16 at 04:53
  • 1
    @gybandi Make your comment an answer and I'll accept it so others with a similar question might see it. – JamesR Jul 07 '16 at 04:56

2 Answers2

4

As I mentioned in my comments, I think the easiest way is to make a cron job on the remote Linux server. You can edit the current cron table by using the crontab -e command. You can check out the cron format here or here.

In your case, it should look something like this:

5 */12 * * * java -jar /path/to/jarfile/filename.jar

This will run the java -jar ... command every 12 hours 5 minute.

After you save it, you can check the existing cron jobs with the crontab -l command. You can also check the syslog for the CRON entries, to see if the job works as intended.

cat /var/log/syslog | grep CRON
gybandi
  • 1,880
  • 1
  • 11
  • 14
2

You can create a task with the help Task Scheduler(Search-> type Task Scheduler). . Create a batch file and provide path of your JDK and jar file. Hope this helps!!!

Damon
  • 64
  • 1
  • 1
  • 10
  • Thanks for your answer, but I am not sure this will work. As it is a Linux server, it needs a 'crontab' file. Appreciate your response though, it put me on the right track for finding the Linux equivalent. – JamesR Jul 07 '16 at 04:58