-
Notifications
You must be signed in to change notification settings - Fork 0
/
monitor.sh
71 lines (62 loc) · 1.76 KB
/
monitor.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
#!/bin/bash
while getopts "l:p:n:h" arg; do
case $arg in
h) echo "(^0^)ノ Hi! "
echo ""
echo "monitor usage:"
echo ""
echo "monitor.sh -l <file.txt> -p <rundir> -n <pipeline>"
echo ""
echo "<file.txt>: a txt file with the GitHub/HTTP links (one link per line);"
echo ""
echo "<rundir>: path to /favorite/dir where <file.txt> is stored;"
echo ""
echo "<pipeline>: the name of your pipeline (to send you a meaningful report)."
echo ""
exit 0
;;
n) pipeline=$OPTARG;;
l) file=$OPTARG;;
p) rundir=$OPTARG;;
esac
done
echo "";
# enter rundir
cd $rundir
# make pipeline dir
mkdir -p $pipeline
cp -r $file $pipeline
cd $pipeline
# Date
time=$(date)
controller () {
exfile=$1
soft=$2
con=$(grep -w Exit $exfile | cut -d":" -f2 | tr -d "[:blank:]")
if [ $con != 0 ]
then
var_sms="${var_sms}${soft}:EXIT; "
else
var_sms="${var_sms}${soft}:OK; "
fi
}
var_sms=""
while read -r link;
do
githubrepo=$(echo $link | grep "github.com" | grep ".git$")
if [ -z "$githubrepo" ]
then
# HTTP link
soft=$(echo $link | rev | cut -d"/" -f1 | rev)
/usr/bin/time -v wget $link 2> $soft.err
controller $soft.err $soft
else
# GitHub link
soft=$(echo $link | rev | cut -d"/" -f1 | rev | cut -d"." -f1)
/usr/bin/time -v git clone --recursive $link 2> $soft.err
controller $soft.err $soft
fi
done < $rundir/$pipeline/$file
var_sms=$(echo "${var_sms/%; /.}")
telcom=$(whereis telegram-send | cut -d":" -f2 | tr -d [:blank:])
$telcom "$time" "LICO report" "Pipeline: $pipeline" "${var_sms}" "The run is over." "Please, remind to delete the directory $rundir/$pipeline to avoid Exit 128 : directory exists at the next run." "Thank you for using LICO. ( ´ ω ` )ノ゙ "