From 772b53aa191a90ca853df9848f7a46eb4c4a974e Mon Sep 17 00:00:00 2001 From: Ayoub Date: Tue, 5 Apr 2022 10:24:41 +0200 Subject: [PATCH] script Bash --- sisr1/40-bash/crsamba1.sh | 10 ++++++++++ sisr1/40-bash/crsamba2.sh | 22 ++++++++++++++++++++++ sisr1/40-bash/crsamba3.sh | 25 +++++++++++++++++++++++++ sisr1/40-bash/crsamba4.sh | 33 +++++++++++++++++++++++++++++++++ sisr1/40-bash/eleve.sh | 20 ++++++++++++++++++++ sisr1/40-bash/rmsamba.sh | 29 +++++++++++++++++++++++++++++ sisr1/40-bash/users.txt | 5 +++++ sisr1/40-bash/users.txt.pwd | 4 ++++ sisr1/40-bash/users2.txt | 4 ++++ 9 files changed, 152 insertions(+) create mode 100755 sisr1/40-bash/crsamba1.sh create mode 100755 sisr1/40-bash/crsamba2.sh create mode 100755 sisr1/40-bash/crsamba3.sh create mode 100755 sisr1/40-bash/crsamba4.sh create mode 100755 sisr1/40-bash/eleve.sh create mode 100755 sisr1/40-bash/rmsamba.sh create mode 100644 sisr1/40-bash/users.txt create mode 100644 sisr1/40-bash/users.txt.pwd create mode 100644 sisr1/40-bash/users2.txt diff --git a/sisr1/40-bash/crsamba1.sh b/sisr1/40-bash/crsamba1.sh new file mode 100755 index 0000000..0713e27 --- /dev/null +++ b/sisr1/40-bash/crsamba1.sh @@ -0,0 +1,10 @@ +#!/bin/bash +#crsamba1 + +fich=users.txt +while read ligne +do + echo "${ligne}" +done < $fich + + diff --git a/sisr1/40-bash/crsamba2.sh b/sisr1/40-bash/crsamba2.sh new file mode 100755 index 0000000..9f043c4 --- /dev/null +++ b/sisr1/40-bash/crsamba2.sh @@ -0,0 +1,22 @@ +#!/bin/bash +#crsamba2 + +#set -e +#set -u + +fich=$1 + +if [[ $# -ne 1 ]] ; then + echo "usage : $0 " + exit 1 +fi + +if [[ ! -r "${fich}" ]] ; then + echo "$0 : Erreur d'ouverture du fichier ${fich}" + exit 2 +fi + +while read ligne +do + echo "${ligne}" +done < $fich diff --git a/sisr1/40-bash/crsamba3.sh b/sisr1/40-bash/crsamba3.sh new file mode 100755 index 0000000..e237535 --- /dev/null +++ b/sisr1/40-bash/crsamba3.sh @@ -0,0 +1,25 @@ +#!/bin/bash +#crsamba2 + +#set -e +#set -u + +fich=$1 + +if [[ $# -ne 1 ]] ; then + echo "usage : $0 " + exit 1 +fi + +if [[ ! -r "${fich}" ]] ; then + echo "$0 : erreur d'ouverture du fichier ${fich}" + exit 2 +fi + +while read ligne +do + login=$(echo "${ligne}"|cut -f1 -d':' ) + long=$(echo "${ligne}"|cut -f2 -d':') + echo "${login} ${long}" + +done < $fich diff --git a/sisr1/40-bash/crsamba4.sh b/sisr1/40-bash/crsamba4.sh new file mode 100755 index 0000000..81cb9dd --- /dev/null +++ b/sisr1/40-bash/crsamba4.sh @@ -0,0 +1,33 @@ +#!/bin/bash +#crsamba2 + +#set -e +#set -u + +fich=$1 + +if [[ $# -ne 1 ]] ; then + echo "usage : $0 " + exit 1 +fi + +if [[ ! -r "${fich}" ]] ; then + echo "$0 : erreur d'ouverture du fichier ${fich}" + exit 2 +fi + +while read ligne + do + login=$(echo "${ligne}"|cut -f1 -d':' ) + long=$(echo "${ligne}"|cut -f2 -d':') + echo "${login} ${long}" + + getent passwd "${login}" >> /dev/null +if [[ $? -ne 0 ]] ; then + useradd -m -d /home/"${login}" -s /bin/bash -c "${nom}" "${login}" + +else + echo "$0 : utilisateur ${login} existant" +fi + +done < ${fich} diff --git a/sisr1/40-bash/eleve.sh b/sisr1/40-bash/eleve.sh new file mode 100755 index 0000000..062ec85 --- /dev/null +++ b/sisr1/40-bash/eleve.sh @@ -0,0 +1,20 @@ +#/bin/bash +#set -e +set -u + +if [[ $# -ne 1 ]] ; then + + exit 1 +fi + +who | grep $1 > /dev/null +if [[ $? -eq 0 ]] ; then + + echo "l'utilisateur $1 est connecté" + +else + echo "l'utilisateur $1 n'est pas connecté" +fi +exit 0 + + diff --git a/sisr1/40-bash/rmsamba.sh b/sisr1/40-bash/rmsamba.sh new file mode 100755 index 0000000..ca9d167 --- /dev/null +++ b/sisr1/40-bash/rmsamba.sh @@ -0,0 +1,29 @@ +#!/bin/bash +#crsamba2 + +#set -e +#set -u + +fich=$1 + +if [[ $# -ne 1 ]] ; then + echo "usage : $0 " + exit 1 +fi + +if [[ ! -r "${fich}" ]] ; then + echo "$0 : erreur d'ouverture du fichier ${fich}" + exit 2 +fi + +while read ligne + do + login=$(echo "${ligne}"|cut -f1 -d':' ) + getent passwd "${login}" >> /dev/null + if [[ $? -eq 0 ]] ; then + sudo userdel --remove "${login}" + echo "Utilisateur ${login} supprime" + +fi + +done < $fich diff --git a/sisr1/40-bash/users.txt b/sisr1/40-bash/users.txt new file mode 100644 index 0000000..c93cc88 --- /dev/null +++ b/sisr1/40-bash/users.txt @@ -0,0 +1,5 @@ +Lucien +Claudine +Robert +Marcelle + diff --git a/sisr1/40-bash/users.txt.pwd b/sisr1/40-bash/users.txt.pwd new file mode 100644 index 0000000..c48f06c --- /dev/null +++ b/sisr1/40-bash/users.txt.pwd @@ -0,0 +1,4 @@ +: +: +: +: diff --git a/sisr1/40-bash/users2.txt b/sisr1/40-bash/users2.txt new file mode 100644 index 0000000..35765b3 --- /dev/null +++ b/sisr1/40-bash/users2.txt @@ -0,0 +1,4 @@ +Lucien:Lucien Aymar +Claudine:Claudine Boudart +Robert:Robert Pascal +Marcelle:Marcelle Dupont