Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
38139b1497 | ||
|
|
116678b2d5 |
@@ -56,3 +56,10 @@ Le script se rafraîchit toutes les `X` secondes.
|
||||
|
||||
---
|
||||
|
||||
|
||||
# GIT
|
||||
|
||||
Etape 1 : modification du code source (vim)
|
||||
Etape 2 : Ajout du fichier pour "versionning" (git add -A)
|
||||
Etape 3 : Versionner le fichier : (git commit -m "UPDATE ..."
|
||||
Etape 4 : Pousser la version sur le server : git push
|
||||
|
||||
+76
-51
@@ -1,59 +1,84 @@
|
||||
#!/bin/bash
|
||||
|
||||
#Utilisation du CPU
|
||||
UsCPU(){
|
||||
top -bn1 | grep Cpu | awk '{print 100-$8}'
|
||||
arg1=$1
|
||||
arg2=$2
|
||||
|
||||
# Script renvoyant les informations système demandees pour ce TP
|
||||
script_demande() {
|
||||
echo "Utilisation du CPU (en %) :"
|
||||
echo "$(top -b -n 1 | grep '%Cpu')"
|
||||
# -n 1 : pour envoyer 1 seule fois l'état (pas en continu)
|
||||
echo "----------"
|
||||
echo "Espace disque (partition /home) :"
|
||||
echo "$(df -h | grep 'Filesystem')"
|
||||
echo "$(df -h | grep '/home')"
|
||||
echo "----------"
|
||||
echo "Nombre de processus actifs (pour tout le system) :"
|
||||
echo "$(($(ps -axf | wc -l) - 3))"
|
||||
# il faut retrancher 3 pour avoir le nombre de processus reel
|
||||
}
|
||||
|
||||
#Espace disponible dans /home
|
||||
SpaceDispo(){
|
||||
df -h /home | grep overlay | awk '{print $4}'
|
||||
# Script perso renvoyant des informations système plus detaillees
|
||||
renvoi_complet() {
|
||||
echo "Nom de la machine : $(hostname)"
|
||||
echo "----------"
|
||||
echo "Systeme exploitation : $(uname -o)"
|
||||
echo "----------"
|
||||
echo "Nom du noyau : $(uname -s)"
|
||||
echo "Version du noyau : $(uname -r)"
|
||||
echo "Type architecture : $(uname -m)"
|
||||
echo "Type CPU : $(uname -p)"
|
||||
echo "Type plateforme materielle : $(uname -i)"
|
||||
echo "----------"
|
||||
echo "Temps ecoule depuis dernier demarrage du systeme : $(uptime -p)"
|
||||
echo "----------"
|
||||
echo "Reseau :"
|
||||
echo "$(ifconfig)"
|
||||
echo "----------"
|
||||
echo "Espace disque total :"
|
||||
echo "$(df -h --total | grep Filesystem)"
|
||||
echo "$(df -h --total | grep total)"
|
||||
echo "----------"
|
||||
echo "Espace disque detaille :"
|
||||
echo "$(df -h)"
|
||||
echo "----------"
|
||||
echo "Utilisation memoire RAM :"
|
||||
echo "$(free -h)"
|
||||
echo "----------"
|
||||
echo "Processus actifs :"
|
||||
echo "$(ps -axf)"
|
||||
}
|
||||
|
||||
#Nombre de processus actifs
|
||||
Procactif(){
|
||||
ps aux --no-header | wc -l
|
||||
}
|
||||
|
||||
#Affichage si -w X
|
||||
|
||||
Affichage(){
|
||||
echo "
|
||||
____________________________________________
|
||||
Monitoring du PC :
|
||||
____________________________________________
|
||||
L'usage du CPU est : $1
|
||||
l'espace disponible dans /home est: $2
|
||||
Il y a $3 processus actif(s)
|
||||
____________________________________________
|
||||
"
|
||||
}
|
||||
|
||||
if [ "$#" -ne 0 ] && [ "$#" -ne 2 ];
|
||||
# Execution du bash
|
||||
if [[ ${arg1} == "-w" ]]
|
||||
then
|
||||
if [[ ${arg2} =~ ^[0-9]+$ ]]
|
||||
then
|
||||
while [ true ]
|
||||
do
|
||||
script_demande
|
||||
sleep ${arg2}
|
||||
clear
|
||||
done
|
||||
else
|
||||
echo "Le second argument doit etre un nombre"
|
||||
fi
|
||||
else
|
||||
echo "Souhaitez-vous le script simple (1) ou complet (2) ?"
|
||||
read reponse
|
||||
if [[ $reponse == "1" ]]
|
||||
then
|
||||
echo "Erreur : Veuillez specifier vos parametres (0 ou2)"
|
||||
exit 1
|
||||
echo "---------------------------------------------------------------------------------"
|
||||
echo "Informations systeme demandees pour le TP"
|
||||
echo "----------"
|
||||
script_demande
|
||||
elif [[ $reponse == "2" ]]
|
||||
then
|
||||
echo "---------------------------------------------------------------------------------"
|
||||
echo "Informations systemes detaillees"
|
||||
echo "----------"
|
||||
renvoi_complet
|
||||
else
|
||||
echo "Reponse non conforme"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ $1 == "-w" ]]
|
||||
then
|
||||
# Rafraichir toutes les $2 secondes
|
||||
while [[ True ]]
|
||||
do
|
||||
#Recupere les variables (changent a chaque iteration)
|
||||
proc=$(UsCPU)
|
||||
space=$(SpaceDispo)
|
||||
nbrproc=$(Procactif)
|
||||
# Raffraichit toutes les $2 secondes
|
||||
Affichage $proc $space $nbrproc
|
||||
sleep $2
|
||||
clear
|
||||
done
|
||||
else
|
||||
# Affichage simple
|
||||
proc=$(UsCPU)
|
||||
space=$(SpaceDispo)
|
||||
nbrproc=$(Procactif)
|
||||
Affichage $proc $space $nbrproc
|
||||
fi
|
||||
|
||||
|
||||
Reference in New Issue
Block a user