留言板

Cron scheduler not executing .sh command

Shashant Panwar,修改在11 年前。

Cron scheduler not executing .sh command

Junior Member 帖子: 28 加入日期: 12-9-21 最近的帖子
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,修改在11 年前。

RE: Cron scheduler not executing .sh command (答复)

Liferay Legend 帖子: 1191 加入日期: 10-3-10 最近的帖子
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,修改在11 年前。

RE: Cron scheduler not executing .sh command

Junior Member 帖子: 28 加入日期: 12-9-21 最近的帖子
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