From dc935ad24bda1d5879892e6d631e93b14919400e Mon Sep 17 00:00:00 2001 From: "alexander.dales@etu.u-bordeaux.fr" Date: Sun, 26 Sep 2021 16:03:40 +0200 Subject: [PATCH] first commit --- script_temp.sh | 105 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100755 script_temp.sh diff --git a/script_temp.sh b/script_temp.sh new file mode 100755 index 0000000..a255f31 --- /dev/null +++ b/script_temp.sh @@ -0,0 +1,105 @@ +#scipt temporaire + +date="$(date +%Y-%m-%d)" +scandir="/home/oscar/scan-souris/" +ecole="/home/oscar/ECOLE/" +nb=0 + +#vérification fichier double +verif () +{ + if [ $1 = "BACKUP" ]; then + while true; do + if [ -e "$scandir${1}/scan_${date}_$nb" ];then + ((nb=$nb+1)) + else + break; + fi + done + # /!\ ceci n'est pas un debug + echo ${scandir}${1}/scan_${date}_$nb + else + while true; do + if [ -e "$ecole${1}/scan_${date}_$nb" ];then + ((nb=$nb+1)) + else + break; + fi + done + # /!\ ceci n'est pas un debug + echo $ecole${1}/scan_${date}_$nb + fi +} + +#scan nouveau fichier +scan () +{ + while true; do + sleep 2 + #ls que les noms puis for mais avec un while + ls -1 /home/oscar/scan-souris | while read -r file; do + echo $? + nb=0 + echo $file + #ne prends pas en compte le dossier backup + if [ $file != "BACKUP" ]; then + #liste les process de l'utilisateur puis ne garde que 2 colonne d'information relative à la commande + ps -u | tr -s " " | cut -d " " -f 11,12 | while read -r process; do + + case $process in + *"maths"*) + echo "math" + path=$( verif MATHS ) + cp $scandir$file $path + echo "$?" + echo "$path" + pathb=$( verif BACKUP ) + mv $scandir$file $pathb + echo "$pathb" + echo "fichier transvasé dans MATHS" + ;; + *"français"*) + path=$( verif FRANCAIS ) + cp $scandir$file $path + pathb=$( verif BACKUP ) + mv $scandir$file $pathb + echo "fichier transvasé dans FRANCAIS" + ;; + *"poésie"*) + path=$( verif POESIE ) + cp $scandir$file $path + pathb=$( verif BACKUP ) + mv $scandir$file $pathb + echo "fichier transvasé dans POESIE" + ;; + *"histoire"*) + path=$( verif HISTOIRE ) + cp $scandir$file $path + pathb=$( verif BACKUP ) + mv $scandir$file $pathb + echo "fichier transvasé dans HISTOIRE" + ;; + *"ergothérapeute"*) + path=$( verif ERGOTHÉRAPEUTE ) + cp $scandir$file $path + pathb=$( verif BACKUP ) + mv $scandir$file $pathb + echo "fichier transvasé dans ERGOTHERAPEUTE" + ;; + # *) + + # pathb=$( verif BACKUP ) + #mv $scandir$file $pathb + #echo "Aucune matière active, fichier placé à : $pathb" + # ;; + esac + done + fi + done + #echo "sortie while" + done +} + +scan + +