Foros de discusión

Cron scheduler not executing .sh command

Shashant Panwar, modificado hace 11 años.

Cron scheduler not executing .sh command

Junior Member Mensajes: 28 Fecha de incorporación: 21/09/12 Mensajes recientes
Hi ,
I have created a liferay cron scheduler and it is working fine.But when I add a '.sh' command to execute along with it then in that case only "receive" method(Scheduler class method) is executing, my script is not executing.Can someone help me with this?
Am I doing something wrong or liferay does not support '.sh' or '.pl' execution in <cron-trigger-value> ?
Here is my code and liferay-portlet.xml entry:

Java Code:

import com.liferay.portal.kernel.messaging.Message;
import com.liferay.portal.kernel.messaging.MessageListener;
import com.liferay.portal.kernel.messaging.MessageListenerException;

public class Schedular implements MessageListener {

int i = 1;
public void receive(Message arg0) throws MessageListenerException {

//Here is the buisness logic to be written as per your requirement
System.out.println("Scheduler has been started; "+ "value is: "+ i);
i++;
}

}

Liferay-portlet.xml entry:
<scheduler-entry>
<scheduler-event-listener-class>com.ys.schedule.Schedular</scheduler-event-listener-class>
<trigger>
<cron>
<cron-trigger-value>0 0/1 * 1/1 * ? * /Users/shashantp/Projects/testFolder/text1.sh</cron-trigger-value>
</cron>
</trigger>
</scheduler-entry>

Thanks & Regards,
Shashant
thumbnail
jelmer kuperus, modificado hace 11 años.

RE: Cron scheduler not executing .sh command (Respuesta)

Liferay Legend Mensajes: 1191 Fecha de incorporación: 10/03/10 Mensajes recientes
You should not add a reference to the script to the cron-trigger-value

You should execute that script from within the receive method of your "Schedular" (sic) using ProcessBuilder or commons-exec
Shashant Panwar, modificado hace 11 años.

RE: Cron scheduler not executing .sh command

Junior Member Mensajes: 28 Fecha de incorporación: 21/09/12 Mensajes recientes
Thanks Jelmer.
Also, Is there any way I can dynamically pass cron values to cron-trigger-value tag or stop it dynamically.
My scenario is: I will receive a file at a location, my job will keep on polling on that directory .the moment job will get the file it wil process it.
Now I want to stop the job the moment my job finds the file and process it,so that it will not process the file recursively as I have a limitation neither I can remove the file nor change the name.
I have to run the job on 24th of every month.

Thanks,
Shashant