remoteUpdate.sh 2.17 KB
#!/bin/bash
# tgt : mercury, venus, mars, jupiter, saturn, neptune, pluto 
# tgt : rosetta, juno 
#  phase : orb, cruise

# sw : OMNI, ACE_RealTime
export DECODER=/home/budnik/depotDECODER

if [[ $# -eq 0 ]] 
then
        echo "[ERROR] : No TARGET defined"
        exit
fi

# Set Generic Environment Variables
. ${DECODER}/env.sh

    tgt=$1    
    if [[ $# -eq 1 ]] 
    then
        echo "[WARNING] No SW input defined : OMNI is used as SW input"
        sw="OMNI"
    else 
        sw=$2
    fi

    # define TARGET_VI
    tgt_vi=$tgt\_orb_all
    if [[ $# -eq 3 ]] 
    then 
        tgt_vi=$tgt\_$3\_all
        echo "[WARNING] Check TARGET_VI : "$tgt_vi
    fi
 
    currDir=`pwd`

    if [[ $tgt != "rosetta" ]]
    then
            tgtMaj=$(echo $tgt | tr [:lower:] [:upper:])
            # Set SW special environment variables
            . swenv.sh $tgtMaj $sw
    else
            . swenv.sh Rosetta $sw
            # use comet Chury as target
            tgt="p67"
    fi

    # Get SW StopTime and Tao StopTime from DDBASE  
    TaoStop=$(php $currDir/getTaoStop.php)
    SwStop=$(php $currDir/getSwStop.php $sw)
    if [[ $TaoStop == 'ERROR' ]] || [[ $SwStop == 'ERROR' ]]
    then
        echo 'ERROR in Tao StopTime or Sw StopTime'
        exit
    fi

    # prepare & run process @ remote;  read its PID into $pid variable
    read -r pid < <(ssh $REMOTEHOST "$SW2ROOT/runRequest $tgt_vi $sw_vi $TaoStop $SwStop")
    echo $pid

    #check if process with PID=$pid is running
    output=INIT  
    startTime=$(date +"%s")    
    while [ ! -z "$output" ] 
        do   
            # check each 10 min             
            sleep 60
            output=$(echo $(ssh -f $REMOTEHOST "ps $pid") | grep $pid)      
            echo  $output 
            stopTime=$(date +"%s")
            t=$(( $stopTime-$startTime ))
            if [ $t -gt 7200 ]
                then
                    echo "[ERROR] Program is terminated because time of computation overcomes 2 hours"
                    ssh $REMOTEHOST "kill -9 $pid"
                    exit 2
            fi  
        done

    # Update local database (DDBASE)
    echo  "UPDATE DATABASE"
    $currDir/updateLocalDataBase $tgt
    cd $currDir