Skip to content

Instantly share code, notes, and snippets.

@DILL44
Created January 31, 2014 11:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DILL44/8730085 to your computer and use it in GitHub Desktop.
Save DILL44/8730085 to your computer and use it in GitHub Desktop.
#!/bin/bash
liste(){
ps -eo "%p %P %r %U %G %y %x %c %C"
ecrire=expr`ps -eo "%p %P %r %U %G %y %x %c %C"`
}
arbre_par_pid(){
read -p "donnez le pid d un processus: " pid
while [ ! "$(echo $pid | grep "^[ [:digit:] ]*$")" ]
do
echo "$processus n'est pas un pid "
read -p "donnez le pid d un processus: " pid
done
if [ "$(echo $pid | grep "^[ [:digit:] ]*$")" ]
then
pstree -Aup $pid
ecrire=expr`pstree -Aup $pid` # 'expr' permet d'affecte a la variable la commande sans l'affichier
else
echo "bug du programme"
fi
}
arbre_par_nom(){
read -p "donnez un processus: " processus
pid=`pgrep $processus`
echo $pid
while [[ -z $pid ]]
do
echo "$processus n'est pas un processus "
read -p "donnez un processus: " processus
pid=`pgrep $processus`
echo $pid
done
if [[ $pid ]]
then
pstree -Aup $pid
ecrire=expr`pstree -Aup $pid` # 'expr' permet d'affecte a la variable la commande sans l'affichier
else
echo "bug du programme"
fi
}
ecrire_fichier(){
read -p "nom du nouveau fichier: " fichier
while [ -e $fichier ]
do
if [ -f $fichier ]
then
echo "$fichier est dans un fichier"
elif [ -d $fichier ]
then
echo "$fichier est un dossier"
else
echo "$fichier existe"
fi
read -p "redonner un nom au nouveau fichier: " fichier
done
echo -e "$ecrire">$fichier # '-e' permet d'interprete les "\n" comme des retour chario
echo "fichier ecrit !!"
}
ligne_separation(){
echo "#######################################################"
}
menu(){
ligne_separation
echo "Quitter: 0"
echo "Lister: 1"
echo "arbre par pid: 2"
echo "arbre par nom: 3"
echo "ecrire dans un fichier: 4"
ligne_separation
}
while [ ! X$choix == X0 ] #'X' permet de ne pas avoir de chaine vide si $choix est vide
do
case $choix in
"1" )ecrire=""; ligne_separation;liste;; # ';' permet d'anchéne les commande sur la meme ligne
"2" )ecrire=""; ligne_separation;arbre_par_pid;;
"3" )ecrire=""; ligne_separation;arbre_par_nom;;
"4" ) ecrire_fichier;;
esac
menu
read -p "choix: " choix
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment