source: trunk/IPs/systemC/processor/Morpheo/Script/execute.sh @ 2

Last change on this file since 2 was 2, checked in by kane, 17 years ago

Import Morpheo

File size: 2.5 KB
Line 
1#!/bin/sh
2
3declare -a COMMAND;
4declare -i CPT_OLD;
5declare -i CPT;
6declare    FILE_CMD=;
7declare    FILE_CPT=;
8declare    FILE_CPU=;
9declare    LOCK_CPT="$HOME/.lock-cpt";
10declare    LOCK_CPU="$HOME/.lock-cpu";
11   
12#-----[ lock ]----------------------------------------------
13function lock ()
14{
15    lockfile -1 $1;
16}
17
18#-----[ unlock ]--------------------------------------------
19function unlock ()
20{
21    rm -f $1;
22}
23
24#-----[ main ]----------------------------------------------
25function main ()
26{
27    # no test, because the script execute_n have make all test
28    FILE_CMD=$1;
29    FILE_CPT=$2;
30    FILE_CPU=$3;
31
32    lock   $LOCK_CPT;
33    if test ! -s $FILE_CPT; then
34        echo "0" > $FILE_CPT;
35    fi;
36    unlock $LOCK_CPT;
37
38    # lit les fichiers ligne par ligne et le place dans un tableau
39    CPT=0;
40
41    while read line; do
42        COMMAND[$CPT]="$line";
43        CPT=$(($CPT+1));
44    done < $1;
45
46    echo "  * <$$> {"`date +"%F %T"`"} is ready";
47
48    # infinite loop
49    CPT_OLD=0;
50    CPT=0;
51
52    while test 1; do
53        # Take a number
54        CPT_OLD=$CPT;
55
56        lock   $LOCK_CPT;
57        CPT=`cat $FILE_CPT`;            # read  the      index
58        echo "$(($CPT+1))" > $FILE_CPT; # write the next index
59        unlock $LOCK_CPT;
60
61        # test if this number is valid
62        if test $CPT -ge ${#COMMAND[*]}; then
63            CPT=${#COMMAND[*]};
64        fi;
65
66        # test if between the cpt_old and cpt, there are a synchronisation command
67
68#       local -i CPT_SYNC=$CPT_OLD;
69#
70#       while test $CPT_SYNC -lt $CPT; do
71#           if test -z "${COMMAND[$CPT_SYNC]}"; then
72#               echo "  * <$$> {"`date +"%F %T"`"} synchronisation [$CPT_SYNC]";
73#           fi;
74#           CPT_SYNC=$(($CPT_SYNC+1));
75#       done;
76
77        # test if this number is valid
78        if test $CPT -eq ${#COMMAND[*]}; then
79            break;
80        fi;
81
82        # Test if command is empty !
83        if test ! -z "${COMMAND[$CPT]}"; then
84            local CUR_DIR=$PWD;
85
86            mkdir "Task_$CPT"       &> /dev/null;
87            cd    "Task_$CPT"       &> /dev/null;
88            echo "  * <$$> {"`date +"%F %T"`"} execute command [$CPT] : ${COMMAND[$CPT]}";
89            echo "${COMMAND[$CPT]}"  >  "command";
90            chmod +x                    "command";
91            eval "${COMMAND[$CPT]}" &"output";
92            cd    $CUR_DIR          &> /dev/null;
93        fi;
94    done;
95
96    echo "  * <$$> {"`date +"%F %T"`"} is done";
97
98    lock   $LOCK_CPU;
99    CPT=`cat $FILE_CPU`;     # read  the      index
100    CPT=$(($CPT-1));
101    echo "$CPT" > $FILE_CPU; # write the next index
102    unlock $LOCK_CPU;
103   
104    if test $CPT -eq 0; then
105        echo "  * <$$> {"`date +"%F %T"`"} All task is executed";
106        rm $FILE_CPU;
107    fi;
108}
109
110#-----[ Corps ]---------------------------------------------
111main $*;
Note: See TracBrowser for help on using the repository browser.