85 lines
2.4 KiB
Bash
85 lines
2.4 KiB
Bash
#!/bin/bash
|
|
|
|
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
|
|
}
|
|
|
|
# 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)"
|
|
}
|
|
|
|
# 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 "---------------------------------------------------------------------------------"
|
|
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
|