[UPDATE] - fork process with screen
This commit is contained in:
parent
5ad25fb23d
commit
304043d02f
4
client/conf-client/Card_10.10.10.3-1666.cfg
Normal file
4
client/conf-client/Card_10.10.10.3-1666.cfg
Normal file
@ -0,0 +1,4 @@
|
||||
10.10.10.3:1666#file#/tmp/coucou
|
||||
10.10.10.3:1666#file#/tmp/nop
|
||||
10.10.10.3:1666#file#
|
||||
10.10.10.3:1666#NotRealSondeName#reboot
|
||||
4
client/conf-client/Card_10.10.10.4-1666.cfg
Normal file
4
client/conf-client/Card_10.10.10.4-1666.cfg
Normal file
@ -0,0 +1,4 @@
|
||||
10.10.10.4:1666#file#/tmp/coucou
|
||||
10.10.10.4:1666#file#/tmp/nop
|
||||
10.10.10.4:1666#file#
|
||||
10.10.10.4:1666#NotRealSondeName#reboot
|
||||
@ -6,22 +6,29 @@ cd $(dirname $0)
|
||||
SondeFile=$(pwd)/sonde.cfg
|
||||
source service.cfg
|
||||
source functions
|
||||
ConfFile=$1
|
||||
|
||||
#[[ "${Crypted}" == "yes" ]] && NcCmd="timeout ${TimeOut} cryptcat -k ${LocalPassword} ${RemoteIp} ${RemotePort} " || NcCmd="timeout ${TimeOut} nc ${RemoteIp} ${RemotePort}"
|
||||
[[ "${Crypted}" == "yes" ]] && NcCmd="timeout ${TimeOut} cryptcat -k ${LocalPassword} " || NcCmd="timeout ${TimeOut} nc "
|
||||
while [[ ! -f /tmp/endmonitor ]]
|
||||
do
|
||||
if [[ -f /tmp/Monithor_${ConfFile}-tmp ]]
|
||||
then
|
||||
|
||||
PrintWeb START_TRATS
|
||||
while read DATA
|
||||
do
|
||||
Remote=$(echo $DATA| cut -d"#" -f1| cut -d":" -f1)
|
||||
Port=$(echo $DATA| cut -d"#" -f1| cut -d":" -f2)
|
||||
Cmd=$(echo $DATA| cut -d"#" -f2)
|
||||
Arg=$(echo $DATA| cut -d"#" -f3)
|
||||
Res=$( echo -e "${Cmd}#${Arg}" | eval ${NcCmd} ${Remote} ${Port} 2> /dev/null)
|
||||
Ret=$?
|
||||
PrintRes "${Res:-5|No sonde $Cmd on serveur $Remote}"
|
||||
PrintWeb "${Res:-5|No sonde $Cmd on serveur $Remote}" ${Cmd:-Nodata} ${Arg:-Noadata} ${Remote:-Nodata}
|
||||
done < ${SondeFile}
|
||||
PrintWeb END_DNE
|
||||
sleep ${Rotation}
|
||||
GenerateWebEnd /tmp/Monithor_${ConfFile}-tmp
|
||||
CheckAllEnd ${TotalConfig}
|
||||
else
|
||||
while read DATA
|
||||
do
|
||||
Remote=$(echo $DATA| cut -d"#" -f1| cut -d":" -f1)
|
||||
Port=$(echo $DATA| cut -d"#" -f1| cut -d":" -f2)
|
||||
Cmd=$(echo $DATA| cut -d"#" -f2)
|
||||
Arg=$(echo $DATA| cut -d"#" -f3)
|
||||
Res=$( echo -e "${Cmd}#${Arg}" | eval ${NcCmd} ${Remote} ${Port} 2> /dev/null)
|
||||
Ret=$?
|
||||
GenerateWeb "${Res:-5|No sonde $Cmd on serveur $Remote}" ${Cmd:-Nodata} ${Arg:-Noadata} ${Remote:-Nodata} /tmp/Monithor_${ConfFile}-tmp
|
||||
done < ${ConfFile}
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
|
||||
@ -5,16 +5,25 @@ PrintRes() {
|
||||
|
||||
}
|
||||
|
||||
PrintWeb() {
|
||||
CheckAllEnd() {
|
||||
|
||||
if [[ ! -f /tmp/webmonithor ]] || [[ "$1" == "START_TRATS" ]]
|
||||
Total=$1
|
||||
Actual=0
|
||||
for AcutalFile in $(find /tmp/ -name Monithor_\*-tmp)
|
||||
do
|
||||
[[ ! -z $(tail -n 1 $ActualFile | grep 'End of') ]] && Acutal=$((Actual + 1))
|
||||
done
|
||||
|
||||
if [[ ${Total} -eq ${Actual} ]]
|
||||
then
|
||||
echo '
|
||||
|
||||
echo '
|
||||
<html>
|
||||
<head>
|
||||
<title>MoniThor on '${RemoteIp}' </title>
|
||||
<meta http-equiv="refresh" content="'${Rotation}'" />
|
||||
</head>
|
||||
<title>MONITHOR</title>
|
||||
|
||||
Date : '$(date +'%Y-%m-%d %H:%M:%S')'
|
||||
|
||||
@ -27,35 +36,48 @@ PrintWeb() {
|
||||
<tbody>
|
||||
' > /tmp/webmonithor
|
||||
|
||||
fi
|
||||
cat /tmp/Monithor_* >> /tmp/webmonithor
|
||||
rm /tmp/Monithor -f
|
||||
|
||||
if [ "$1" == "END_DNE" ]
|
||||
then
|
||||
echo '
|
||||
|
||||
echo '
|
||||
</tbody>
|
||||
</table> ' >> /tmp/webmonithor
|
||||
mv /tmp/webmonithor ../web/index.html
|
||||
mv /tmp/webmonithor ../web/index.html
|
||||
|
||||
else
|
||||
|
||||
Val=$(echo $1 | cut -d"|" -f1)
|
||||
Txt=$(echo $1 | cut -d"|" -f2)
|
||||
Sonde=$2
|
||||
Arg=$3
|
||||
Remote=$4
|
||||
Color=red
|
||||
[[ $Val == "0" ]] && Color=green
|
||||
[[ $Val == "1" ]] && Color=yellow
|
||||
fi
|
||||
}
|
||||
|
||||
echo '
|
||||
GenerateWebEnd(){
|
||||
echo '<!--End of '$1'-->'| tee -a $1
|
||||
|
||||
}
|
||||
|
||||
GenerateWeb(){
|
||||
|
||||
Val=$(echo $1 | cut -d"|" -f1)
|
||||
Txt=$(echo $1 | cut -d"|" -f2)
|
||||
Sonde=$2
|
||||
Arg=$3
|
||||
Remote=$4
|
||||
File=$5
|
||||
Color=red
|
||||
[[ $Val == "0" ]] && Color=green
|
||||
[[ $Val == "1" ]] && Color=yellow
|
||||
|
||||
echo '
|
||||
<tr>
|
||||
<td>'$Remote'</td>
|
||||
<td>'$Sonde'</td>
|
||||
<td>'$Arg'</td>
|
||||
<td style="background-color:'${Color}';" > '$Val' </td>
|
||||
<td> '$Txt'</td>
|
||||
</tr>' >> /tmp/webmonithor
|
||||
fi
|
||||
</tr>' >> ${File}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@ -2,3 +2,7 @@
|
||||
10.10.10.3:1666#file#/tmp/nop
|
||||
10.10.10.3:1666#file#
|
||||
10.10.10.3:1666#NotRealSondeName#reboot
|
||||
10.10.10.4:1666#file#/tmp/coucou
|
||||
10.10.10.4:1666#file#/tmp/nop
|
||||
10.10.10.4:1666#file#
|
||||
10.10.10.4:1666#NotRealSondeName#reboot
|
||||
|
||||
@ -1,17 +1,26 @@
|
||||
#!/bin/bash
|
||||
|
||||
|
||||
source $(dirname $0)/conf-client/service.cfg
|
||||
source $(dirname $0)/conf-client/functions
|
||||
|
||||
if [[ -z $(ps axf| grep pyhton | grep ${WebPort}) ]]
|
||||
if [[ "$1" == "start" ]]
|
||||
then
|
||||
[[ -f /tmp/endmonitor ]] && rm -f /tmp/endmonitor
|
||||
bash ./conf-client/webserver.sh ${WebPort} &
|
||||
fi
|
||||
|
||||
while true
|
||||
do
|
||||
./conf-client/exec.sh
|
||||
sleep $Rotation
|
||||
done
|
||||
export TotalConfig=$(ls -1 ./conf-client | grep Card_.*\.cfg|wc -l)
|
||||
for Conf in $(ls -1 ./conf-client | grep Card_.*\.cfg)
|
||||
do
|
||||
screen -dmS ${Conf} bash -x ./conf-client/exec.sh ${Conf}
|
||||
done
|
||||
|
||||
fi
|
||||
|
||||
if [[ "$1" == "stop" ]]
|
||||
then
|
||||
killall python
|
||||
rm /tmp/Monithor*
|
||||
touch /tmp/endmonitor
|
||||
|
||||
fi
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user