[UPDATE] - fork process with screen

This commit is contained in:
Prof Isen 2022-03-16 15:22:09 +00:00
parent 5ad25fb23d
commit 304043d02f
6 changed files with 92 additions and 42 deletions

View 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

View 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

View File

@ -6,22 +6,29 @@ cd $(dirname $0)
SondeFile=$(pwd)/sonde.cfg SondeFile=$(pwd)/sonde.cfg
source service.cfg source service.cfg
source functions 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 " [[ "${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 sleep ${Rotation}
while read DATA GenerateWebEnd /tmp/Monithor_${ConfFile}-tmp
do CheckAllEnd ${TotalConfig}
Remote=$(echo $DATA| cut -d"#" -f1| cut -d":" -f1) else
Port=$(echo $DATA| cut -d"#" -f1| cut -d":" -f2) while read DATA
Cmd=$(echo $DATA| cut -d"#" -f2) do
Arg=$(echo $DATA| cut -d"#" -f3) Remote=$(echo $DATA| cut -d"#" -f1| cut -d":" -f1)
Res=$( echo -e "${Cmd}#${Arg}" | eval ${NcCmd} ${Remote} ${Port} 2> /dev/null) Port=$(echo $DATA| cut -d"#" -f1| cut -d":" -f2)
Ret=$? Cmd=$(echo $DATA| cut -d"#" -f2)
PrintRes "${Res:-5|No sonde $Cmd on serveur $Remote}" Arg=$(echo $DATA| cut -d"#" -f3)
PrintWeb "${Res:-5|No sonde $Cmd on serveur $Remote}" ${Cmd:-Nodata} ${Arg:-Noadata} ${Remote:-Nodata} Res=$( echo -e "${Cmd}#${Arg}" | eval ${NcCmd} ${Remote} ${Port} 2> /dev/null)
done < ${SondeFile} Ret=$?
PrintWeb END_DNE GenerateWeb "${Res:-5|No sonde $Cmd on serveur $Remote}" ${Cmd:-Nodata} ${Arg:-Noadata} ${Remote:-Nodata} /tmp/Monithor_${ConfFile}-tmp
done < ${ConfFile}
fi
done

View File

@ -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 then
echo '
echo '
<html> <html>
<head> <head>
<title>MoniThor on '${RemoteIp}' </title> <title>MoniThor on '${RemoteIp}' </title>
<meta http-equiv="refresh" content="'${Rotation}'" /> <meta http-equiv="refresh" content="'${Rotation}'" />
</head> </head>
<title>MONITHOR</title>
Date : '$(date +'%Y-%m-%d %H:%M:%S')' Date : '$(date +'%Y-%m-%d %H:%M:%S')'
@ -27,35 +36,48 @@ PrintWeb() {
<tbody> <tbody>
' > /tmp/webmonithor ' > /tmp/webmonithor
fi cat /tmp/Monithor_* >> /tmp/webmonithor
rm /tmp/Monithor -f
if [ "$1" == "END_DNE" ]
then
echo '
echo '
</tbody> </tbody>
</table> ' >> /tmp/webmonithor </table> ' >> /tmp/webmonithor
mv /tmp/webmonithor ../web/index.html mv /tmp/webmonithor ../web/index.html
else
Val=$(echo $1 | cut -d"|" -f1) fi
Txt=$(echo $1 | cut -d"|" -f2) }
Sonde=$2
Arg=$3
Remote=$4
Color=red
[[ $Val == "0" ]] && Color=green
[[ $Val == "1" ]] && Color=yellow
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> <tr>
<td>'$Remote'</td> <td>'$Remote'</td>
<td>'$Sonde'</td> <td>'$Sonde'</td>
<td>'$Arg'</td> <td>'$Arg'</td>
<td style="background-color:'${Color}';" > '$Val' </td> <td style="background-color:'${Color}';" > '$Val' </td>
<td> '$Txt'</td> <td> '$Txt'</td>
</tr>' >> /tmp/webmonithor </tr>' >> ${File}
fi
} }

View File

@ -2,3 +2,7 @@
10.10.10.3:1666#file#/tmp/nop 10.10.10.3:1666#file#/tmp/nop
10.10.10.3:1666#file# 10.10.10.3:1666#file#
10.10.10.3:1666#NotRealSondeName#reboot 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

View File

@ -1,17 +1,26 @@
#!/bin/bash #!/bin/bash
source $(dirname $0)/conf-client/service.cfg 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 then
[[ -f /tmp/endmonitor ]] && rm -f /tmp/endmonitor
bash ./conf-client/webserver.sh ${WebPort} & bash ./conf-client/webserver.sh ${WebPort} &
fi
while true export TotalConfig=$(ls -1 ./conf-client | grep Card_.*\.cfg|wc -l)
do for Conf in $(ls -1 ./conf-client | grep Card_.*\.cfg)
./conf-client/exec.sh do
sleep $Rotation screen -dmS ${Conf} bash -x ./conf-client/exec.sh ${Conf}
done done
fi
if [[ "$1" == "stop" ]]
then
killall python
rm /tmp/Monithor*
touch /tmp/endmonitor
fi