#!/bin/bash

MINBASE=/usr/local/minerva
VARLOG=/var/log/minerva
MINLOG=$VARLOG/rlyexec

date +"%F %H:%M CMD $0 $*" >>$VARLOG/bearskin/`basename $0`

if [ $# == 0 ]; then
  echo "Usage: $0 [conduit] [user] <command> <arguments>"
fi

CONDUIT=$1; shift
USER=$1; shift
COMMAND=$1; shift
ARGUMENTS=$*

RELAYPATH=$MINBASE/etc/users/$USER/relay/$CONDUIT

if [ -d $RELAYPATH ]; then
   FILELIST=`ls -1 $RELAYPATH`

   for FILE in `ls -1 $RELAYPATH`; do
     FULLNAME="$RELAYPATH/$FILE"
     if [ -x $FULLNAME ]; then
       $FULLNAME $COMMAND $ARGUMENTS
       if [[ $? -ne 0 ]]; then
          break
       fi
     fi
   done
fi



