-
Notifications
You must be signed in to change notification settings - Fork 29
/
run-scripts
executable file
·46 lines (39 loc) · 1.1 KB
/
run-scripts
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
#!/bin/bash
LOGS=/var/log/tioupd
mkdir -p "$LOGS"
formattime() {
if [ $1 -lt 60 ]; then
echo "$1s"
else
echo "$((${1}/60))m $((${1}%60))s"
fi
}
if [ $# -lt 1 ]; then
echo "Usage: run-scripts <dir>"
exit 1
fi
if [ ! -d $1 ]; then
echo "Not a directory: $1"
exit 1
fi
for i in $(LC_ALL=C; echo ${1%/}/*) ; do
[ -d $i ] && continue
if [ -x $i ]; then
# run executable files
echo "$(date --rfc-3339=seconds) run-scripts[$$] ($1) starting $(basename $i)" >> "$LOGS/run-scripts.log"
echo "$(date --rfc-3339=seconds) Executing $(basename $i)..."
start=`date +%s`
echo "$(date --rfc-3339=seconds)" >> "$LOGS/$(basename $i).log"
$i >> "$LOGS/$(basename $i).log" 2>&1
status="$?"
end=`date +%s`
if [ "$status" -eq "0" ]; then
status="SUCCESS"
else
status="FAILURE: $status"
fi
echo "$(date --rfc-3339=seconds) Executed $(basename $i)... $(formattime $((end-start))) {$status}"
echo "$(date --rfc-3339=seconds) run-scripts[$$] ($1) finished $(basename $i) $(formattime $((end-start))) {$status}" >> "$LOGS/run-scripts.log"
fi
done
exit 0