Jump to content
egoistdream

Program monitorizare screen

Recommended Posts

Posted (edited)

Un program care iti verifica daca un screen e pornit la un anumit interval de timp...in cazul in care nu este pornit iti executa o comanda(iti poate reporni screenul)...binenteles ca se putea face lucrul asta si cu crontab dar la un interval de minim 1 minut....scriptul meu poate verifica un screen si la un interval de o secunda....e adevarat ca pentru adevaratii programatori nu are valoare scriptul asta dar sper sa ajute pe cineva.

Pasii pe care trebuie sa ii urmezi:

1 Downloadati scriptul de la adresa DreamServer sau MegaUpload (wget http://dreamserver.ro/dream.sh)

2 Creati un folder unde vreti voi in care trebuie sa se afle doua fisiere:

-a. scriptul downloadat

-b. un script (obligatoriu) cu numele "start", care sa contina comanda care va fi executata in cazul in care screenul pe care vreti sa il monitorizati este oprit.(de exemplu: cd /home/server/ && screen -m -d -A -S server ./serverumeu)

3 Verificati ca cele 2 fisiere sunt executabile (chmod +x)

4 Porniti scriptul dream.sh in care precizati numele screenului care va fi monitorizat si intervalul.Scriptul dream.sh il puteti porni de asemenea intr un screen (exemplu pornire in screen: screen -m -d -A -S monitorizarescreen ./dream.sh serverulmeu 30)

sper ca pe viitor sa ii pot aduce mai multe functii

scripta.png

Codul sursa


#!/bin/bash
SCREEN=$1
TIMP=$2
# =========== FUNCTII ===========
function print_info(){
echo " >> $1"
}
function force_exit(){ # in caz de eroare
echo " >> $1, Inchid programul..."
echo " >> Exemplu: $0 [numescreen] [secunde]"
exit 1 # eroare
}
function safe_exit(){
echo " >> Inchid programul..."
exit 0
}
# =========== IMPLEMENTARE ===========
if [ $# -lt 2 ]; then
force_exit "Numar prea mic de parametrii"
fi
if [ $# -gt 2 ]; then
force_exit "Numar prea mare de parametrii"
fi
##############################################################
echo "
_____ _____
| __ \ / ____|
| | | |_ __ ___ __ _ _ __ ___ | (___ ___ _ ____ _____ _ __
| | | | __/ _ \/ _ | _ _ \ \___ \ / _ \ __\ \ / / _ \ __|
| |__| | | | __/ (_| | | | | | |____) | __/ | \ V / __/ |
|_____/|_| \___|\__ _|_| |_| |_|_____/ \___|_| \_/ \___|_|

*****************************************************************************
***** Gazduire servere de cs 32 sloturi port 27015 la doar 50lei/luna *****
***** Gazduire servere de cs 32 sloturi port 28015 la doar 30lei/luna *****
***** Gazduire servere de cs 32 sloturi port 26015 la doar 30lei/luna *****
***** Gazduire servere de Sa-Mp 50 sloturi port 7777 doar 30lei/luna *****
***** Reseller Web 5 gb spatiu maxim 25 clienti la doar 25 lei/luna *****
**********************Script realizat de Cristian****************************
**************************** DreamServer.ro *******************************
************* Contact: Cristian@DreamServer.ro YM! cristian8357**************
*****************************************************************************

-----------------------------------------------------------------------------
Verific la fiecare $2 secunde daca screenul $1 este pornit.
"

id=1
while [ $1 = $1 ]
do
if test `screen -r | grep $1 | wc -l` -eq 1; then
echo $id."Screenul $1 este pornit";
else
echo $id.`date +%H:%M` "Am executat comanda ./start deoarece screenul $1 era oprit"
./start
fi
(( id++ ))
sleep $2
done
safe_exit

Edited by egoistdream
Posted

#!/bin/sh

# myapp.pid - pid-ul aplicatiei.

# MYPATH - full path catre aplicatie

# myapp - aplicatia mea

# pune-ma in crontab :D

MYPATH=/usr/home/tex/work

if test -r $MYPATH/myapp.pid; then

# inseamna ca ruleaza aplicatia

else

# nu ruleaza, hai sa o pornim

cd $MYPATH && ./myapp -p myapp.pid

fi

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...