script-part-souris-scan/script_temp.sh

108 lines
2.7 KiB
Bash
Raw Permalink Normal View History

2021-09-26 16:03:40 +02:00
#scipt temporaire
date="$(date +%Y-%m-%d)"
scandir="/home/oscar/scan-souris/"
ecole="/home/oscar/ECOLE/"
nb=0
#vérification fichier double
verif ()
{
2021-09-26 16:21:23 +02:00
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
2021-09-26 16:03:40 +02:00
while true; do
2021-09-26 16:21:23 +02:00
if [ -e "$ecole${1}/scan_${date}_$nb" ];then
((nb=$nb+1))
else
break;
fi
2021-09-26 16:03:40 +02:00
done
2021-09-26 16:21:23 +02:00
# /!\ ceci n'est pas un debug
echo $ecole${1}/scan_${date}_$nb
fi
2021-09-26 16:03:40 +02:00
}
#scan nouveau fichier
scan ()
{
2021-09-26 16:21:23 +02:00
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
2021-10-04 20:00:02 +02:00
no_bool=0
2021-09-26 16:21:23 +02:00
#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; done
case $process in
*"maths"*)
path=$( verif MATHS )
cp $scandir$file $path
pathb=$( verif BACKUP )
mv $scandir$file $pathb
echo "fichier transvasé dans MATHS"
2021-10-04 17:25:07 +02:00
no_bool=1
2021-09-26 16:21:23 +02:00
;;
2021-09-26 16:03:40 +02:00
*"français"*)
2021-09-26 16:21:23 +02:00
path=$( verif FRANCAIS )
cp $scandir$file $path
pathb=$( verif BACKUP )
mv $scandir$file $pathb
echo "fichier transvasé dans FRANCAIS"
2021-10-04 17:25:07 +02:00
no_bool=1
2021-09-26 16:21:23 +02:00
;;
2021-09-26 16:03:40 +02:00
*"poésie"*)
2021-09-26 16:21:23 +02:00
path=$( verif POESIE )
cp $scandir$file $path
pathb=$( verif BACKUP )
mv $scandir$file $pathb
echo "fichier transvasé dans POESIE"
2021-10-04 17:25:07 +02:00
no_bool=1
2021-09-26 16:21:23 +02:00
;;
2021-09-26 16:03:40 +02:00
*"histoire"*)
2021-09-26 16:21:23 +02:00
path=$( verif HISTOIRE )
cp $scandir$file $path
pathb=$( verif BACKUP )
mv $scandir$file $pathb
echo "fichier transvasé dans HISTOIRE"
2021-10-04 17:25:07 +02:00
no_bool=1
2021-09-26 16:21:23 +02:00
;;
*"ergothérapeute"*)
path=$( verif ERGOTHÉRAPEUTE )
cp $scandir$file $path
pathb=$( verif BACKUP )
mv $scandir$file $pathb
echo "fichier transvasé dans ERGOTHERAPEUTE"
2021-10-04 17:25:07 +02:00
no_bool=1
2021-09-26 16:21:23 +02:00
;;
esac
done
if [ no_bool == 0 ]; then
path=$( verif SCAN )
cp $scandir$file $path
pathb=$( verif BACKUP )
mv $scandir$file $pathb
echo "aucune matière lancée, fichier tranvasé dans SCAN"
fi
2021-09-26 16:21:23 +02:00
fi
done
#echo "sortie while"
done
2021-09-26 16:03:40 +02:00
}
scan