0

I need to execute a java program in shell looply.

The program is really basic. I'm getting an access token and I'm using it to make a simple POST request.

My problem :

  • I need to refresh the access token every 55 minutes (the token has an hour expiration)
  • I need to make the POST every 5 min

I don't know which timer I should use in my shell command(and in my code ?)

If I put 5 min, this will refresh the token every 5 min...

Sorry I didn't provide any code, it's just an issue I don't know how to solve.

Thanks !

3
  • why don't you put the loop in your java app? Commented Feb 21, 2018 at 11:08
  • 3
    Use cron, not a loop Commented Feb 21, 2018 at 11:09
  • 1
    Use cron jobs to run your bash script. Commented Feb 21, 2018 at 11:12

2 Answers 2

1

If you are working in Linux you may use cron: Edit the /etc/crontab file and add a new line like this:

*/5 * * * * java -jar <your jar> <params>

This will run your program every 5 minutes.

Sign up to request clarification or add additional context in comments.

Comments

0

Not sure I understood correctly. In bash you would like something like:

#!/bin/bash

while true; do
echo "refresh token";
a=0;

while true; do

  echo "doing post"
  echo "sleeping 5 minutes here"
  sleep 300;
  a=$[$a+1]

  if [ $a -eq 11 ]; then
    a=0
    echo "refreshing token again"
  fi

done;

done

Just translate it to java.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.