stopsim() { echo "checking for pid file: $PIDFILE" if [ -f $PIDFILE ] then running=`ps aux | grep $NAME | grep $(cat $PIDFILE) -c` if [ $running -eq 0 ] then echo Simulation not running else echo "Killing Simulation $(cat $PIDFILE)" kill $(cat $PIDFILE) echo stoped Simulation fi rm $PIDFILE fi true } stopsim_and_exit() { if [ $DATA_DIRECTORY ] && [ -d $DATA_DIRECTORY ]; then PIDFILE=$DATA_DIRECTORY/$NAME.pid stopsim echo "exiting now." exit 0 fi } set_default_data_dir() { i="0" while [ -d $DATA_DIR_BASE$i ] do i=$[$i+1] done DATA_DIRECTORY=$DATA_DIR_BASE$i echo "setting data directory to: $DATA_DIRECTORY" } create_datadirectory() { if [ ! $DATA_DIRECTORY ] then set_default_data_dir fi if [ ! -d $DATA_DIRECTORY ] then echo "create data directory: $DATA_DIRECTORY" mkdir -p $DATA_DIRECTORY fi ERROR=$? if [ $ERROR -ne "0" ] then exit 1 fi } USAGE="Usage: `basename $0` [-h] [-d data_dir] args_forwarded_to_simulation" while [ ! $STOP ] do if [ $# -eq 0 ] || [[ "$1" =~ "--" ]] then STOP=true else echo "para=$1" case "$1" in "-d") DATA_DIRECTORY=$2 echo "directory = $2" shift ;; "-h") echo $USAGE exit 0 ;; "stop") STOP=true stopsim_and_exit ;; esac shift fi done create_datadirectory PIDFILE=$DATA_DIRECTORY/$NAME.pid stopsim SIM_PARAMETERS="--DataDirectory $DATA_DIRECTORY $*" nohup nice -10 ./$NAME $SIM_PARAMETERS >$DATA_DIRECTORY/simoutput.txt 2>$DATA_DIRECTORY/simerror.txt & echo $! > $PIDFILE echo started simulation with parameters: $SIM_PARAMETERS