-
Notifications
You must be signed in to change notification settings - Fork 0
/
y.sh
115 lines (106 loc) · 6.16 KB
/
y.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/bin/bash
# Fred Denis -- Oct 23rd 2019 -- ERS-143
#
# Use of makefiles to schedule jobs
#
# - Parse a JSON file containing the list of jobs, dependencies, etc ...
# - Use json.tool to make it more usable
# - Generate the makefile with the jobs and the dependencies
# - Use make to execute the job, make taking care of the //, dependencies, etc ...
#
# The current version of the script is in dev
#
# 20190223 - Fred Denis - Dev starting
#
IN=json.txt # JSON input file
TMP=/tmp/fictemp$$ # A tempfile
# To specify a special job -- to be replaced by getopts
MASTER="$1"
if [[ -z $1 ]]
then
MASTER="."
fi
python -m json.tool ${IN} | sed s'/[",]//g' | sed s'/ *//' |\
awk -v MASTER="${MASTER}"\
'BEGIN { FS=":";
srand() ;
}
function print_txt_ts(in_txt)
{ # Print a "@echo <TXT> <TIMESTAMP>" line
printf("\t%s\n", "@echo -e \"" in_txt "\""" $(TS)") ;
#printf("\t%s\n", "@echo -e \"" in_txt "\"" $(TS)") ;
}
{ if (($1 == "name") && ($2 ~ MASTER))
{ master=tolower($2) ;
gsub (" ", "", master) ;
printf ("%s\n", "TS := `/bin/date \"+%Y-%m-%d-%H-%M-%S\"`") ;
printf ("%s: %s\n", "done", "end-"master) ;
printf("%s:\n", master)
#printf("\t%s\n", "echo \"starting " master "\" && sleep 1") ;
#printf("\t%s\n", "@echo \"Begin " master "\""" $(TS)") ;
print_txt_ts("Begin " master) ;
while(getline)
{
if ($1 == "nodes")
{ while(getline)
{ if ($1 == "dependencies")
{ dep = "" ;
if ($2 ~ /\[\]/)
{ dep = master ;
} else
{ while(getline)
{
if ($1 ~ /^\]/)
{ break ;
}
if (dep == "")
{ dep = master"-"$0 ;
} else
{
dep = dep" "master"-"$0 ;
}
}
}
}
if ($1 == "name")
{ gsub("^ ", "", dep) ;
name = $2 ;
gsub(" ", "", name) ;
printf("%s: %s\n", master"-"name, dep) ;
#printf("\t%s\n", "echo \"Starting............. "name"\" && sleep 5") ;
#printf("\t%s\n", "echo -e \"Starting............. "name"\" && sleep 5") ;
print_txt_ts("\\tBegin "master"-"name ) ;
x=int((rand()*100));
if (x>60){x=x-60};
print_txt_ts("\\t"master"-"name " sleeps for " x " seconds" ) ;
printf("\t%s\n", "sleep " x) ;
print_txt_ts("\\tEnd "master"-"name ) ;
end_name=master"-"name" "end_name ;
}
if ($1 == "timeout")
{
break ;
}
}
}
if ($1 == "timeout")
{
printf("%s: %s\n", "end-"master, end_name) ;
#printf("\t%s\n", "echo all done && sleep 1") ;
printf("\t%s\n", "@echo \"End " master "\""" $(TS)") ;
printf ("\n") ;
break ;
}
}
}
}
' > ${TMP}
#cat $TMP
make -j -f ${TMP}
if [[ -f ${TMP} ]]
then
rm -f ${TMP}
fi
#****************************************************************#
#* E N D O F S O U R C E *#
#****************************************************************#