Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Shashant Panwar
Cron scheduler not executing .sh command
January 11, 2013 1:52 PM
Answer

Shashant Panwar

Rank: New Member

Posts: 19

Join Date: September 21, 2012

Recent Posts

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
Jelmer Kuperus
RE: Cron scheduler not executing .sh command
January 13, 2013 1:38 AM
Answer

Jelmer Kuperus

Rank: Liferay Legend

Posts: 1190

Join Date: March 10, 2010

Recent Posts

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
RE: Cron scheduler not executing .sh command
January 14, 2013 9:08 PM
Answer

Shashant Panwar

Rank: New Member

Posts: 19

Join Date: September 21, 2012

Recent Posts

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