I am trying to run a cronjob every 5 mins, the actual task is to trigger a curl end point from within the java class in a method. my crontab -e looks like below: */5 * * * * bash /home/ec2-user/script.sh the above line is working fine but it is not triggering the FTPConnect.start() from the Cron job class my Cron job looks like below: @Component public class CJob{
@Scheduled(cron="*/5 * * * * curl -v http://localhost:8080/apiname/v1/cids/$filename" ) // Every 12 hours
public static void fetchFromSFTP() {
try {
FTPConnect.start();
return;
} catch (Exception e) {
System.out.println("There was an error running this cron.");
e.printStackTrace();
System.exit(1);
}
}
}
question from:https://stackoverflow.com/questions/66068256/how-to-trigger-a-java-function-or-a-class-from-crontab-e