Thursday, November 14, 2013

Running DBus in Crontab

Just create an sh file to execute your script. example See below:

xhost +
export DBUS_SESSION_BUS_ADDRESS=$(cat /home/iben/.dbus/session-bus/f49d2a1187871a80e2a3bb640000000a-0|grep unix|cut -d= -f2-4)

ps -ef | grep -v grep | grep chat.php
# if not found - equals to 1, start it
if [ $? -eq 1 ]
/usr/bin/php /home/iben/www/tes/dbus/chat.php&
echo "eq 0 - chat.php found - do nothing"
xhost + is required

export DBUS_SESSION_BUS_ADDRESS=$(cat /home/iben/.dbus/session-bus/f49d2a1187871a80e2a3bb640000000a-0|grep unix|cut -d= -f2-4) ==> is required to inform cron of session location.

f49d2a1187871a80e2a3bb640000000a-0 ==> is a long name that is different with your. Usually have pattern like *a-0, a file in directory /home/username/dbus/sessiom-bus/*a-0. Find your.

Sintax after it is your own script. Here I use script to check existing process. if not exist then run the php script. Else don't do anything.

chat.php is a script that use DBus class.

Simply add to cron like this:
* * * * * sh /home/iben/www/tes/dbus/ > /home/iben/www/tes/dbus/chat.log

It will check process every minute. It better than use 'php flock'.


Post a Comment