将JAVA程序添加至系统服务

#!/bin/sh

### BEGIN INIT INFO
# Provides: java service
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start up the java service daemon.
# Description:       Start up the java service daemon.
### END INIT INFO

BASE_DIR="/home/yangxianchao/pq"
PID=$(ps -ef | grep com/st/pq/SendComments | awk '{if($3==1){print $2}}')

cd $BASE_DIR

start(){
  if [ "$PID" == "" ]
  then
    for i in *.jar
    do
      CLASS_PATH=$CLASS_PATH:$i
    done
    java -cp $CLASS_PATH com/st/pq/SendComments > /dev/null 2>&1 &
    sleep 1
    echo "Start."
  else
    echo "It's running."
  fi
}
stop(){
  if [ "$PID" == "" ]
  then
    echo "It's not running."
  else
    kill $PID
    sleep 1
    echo "Stop."
  fi
}
status(){
  if [ "$PID" == "" ]
  then
    echo "stop"
  else
    echo "running"
  fi
}
case $1 in
  start)
    start
  ;;
  stop)
    stop
  ;;
  status)
    status
  ;;
  *)
    echo "start|stop|status"
  ;;
esac

求两个日期区间段的交集

$t1 = strtotime('2013-07-01 00:00:00');
$t2 = strtotime('2013-07-10 23:59:59');
$s  = strtotime('2013-07-05 00:00:00');
$e  = strtotime('2013-07-15 23:59:59');

$xs = date( 'Y-m-d H:i:s', $t1 > $s ? $t1 : $s );
$xe = date( 'Y-m-d H:i:s', $t2 < $e ? $t2 : $e );
if( ($s >= $t1 && $s < = $t2) || ($t1 >= $s && $t1 < = $e) ){
	echo $xs, ' ', $xe, "\r\n";
}

$xs = $t1 > $s ? $t1 : $s ;
$xe = $t2 < $e ? $t2 : $e ;
if($xs <= $xe){
	echo date('Y-m-d H:i:s', $xs), ' ', date('Y-m-d H:i:s', $xe), "\r\n";
}