#!/bin/bash MCORE_LIBDIR="@@MCORE_LIBDIR@@" source @@SYSCONFDIR@@/mcore/mcore.conf source @@SYSCONFDIR@@/mcore/citrix.conf source @@SYSCONFDIR@@/mcore/citrix-enumerate.conf source @@SYSCONFDIR@@/mcore/control.conf source ${MCORE_LIBDIR}/include/common.global.class source ${MCORE_LIBDIR}/include/daemon.global.class source ${MCORE_LIBDIR}/include/mysqlfunctions.global.class : ${CITRIX_BROWSER=""} : ${CITRIX_USER=""} : ${CITRIX_PASS=""} : ${CITRIX_DOMAIN=""} export IMPORTED_IDS="" LOCKFILE="@@RUNDIR@@/citrix-cron.lock" is_not_an_import_id() { local id="$1" local entry for entry in ${IMPORTED_IDS} do if [[ ${entry} = ${id} ]] then return 1 fi done return 0 } # the lockfile is not meant to be perfect, it's just in case the # two cron scripts get run close to each other to keep # them from stepping on each other's toes. [[ -f ${LOCKFILE} ]] && exit 0 trap "{ rm -f ${LOCKFILE}; exit 0; }" EXIT touch ${LOCKFILE} # get default settings from configs [[ -z ${CITRIX_BROWSER} ]] && export CITRIX_BROWSER="${PNABROWSE_CITRIX_BROWSER}" [[ -z ${CITRIX_USER} ]] && export CITRIX_USER="${MCORE_CITRIX_USER}" [[ -z ${CITRIX_PASS} ]] && export CITRIX_PASS="${MCORE_CITRIX_PASS}" [[ -z ${CITRIX_DOMAIN} ]] && export CITRIX_DOMAIN="${MCORE_CITRIX_DOMAIN}" OPT="" [[ -n ${CITRIX_USER} ]] && OPT+=" -U ${CITRIX_USER}" [[ -n ${CITRIX_PASS} ]] && OPT+=" -P ${CITRIX_PASS}" [[ -n ${CITRIX_DOMAIN} ]] && OPT+=" -D ${CITRIX_DOMAIN}" SESSION_LIST=$(pnabrowse -A ${OPT} ${CITRIX_BROWSER} 2> /dev/null) if [[ $? != 0 ]] then echo "could not retrieve session list" exit 1 fi # exclude the desktop session, which is always the first declare -i counter=0 while read line do if [[ ${counter} -gt 0 ]] then session=$(echo ${line} | cut -d"'" -f 2) description="" # import or update db entry id=$(mysqldo "select id from values_citrix_session where session='${session}';") if [[ -z ${id} ]] then mysqldo "insert into values_citrix_session (session,description,enabled) values('${session}','${description}','1');" else mysqldo "update values_citrix_session set session='${session}',description='${description}',enabled='1' where id='${id}';" fi # get and save id id=$(mysqldo "select id from values_citrix_session where session='${session}';") export IMPORTED_IDS+=" ${id}" fi (( counter++ )) done << EOF $(echo "${SESSION_LIST}") EOF # now disable all other ids in the database DATABASE_IDS=$(mysqldo "select id from values_citrix_session") for id in ${DATABASE_IDS} do if is_not_an_import_id "${id}" then # disable this one, not imported=not existing on the storefront-server in the moment mysqldo "update values_citrix_session set enabled='0' where id='${id}';" fi done exit 0