From d6c39be117defbe549bc4a3fd28eeb92531e27be Mon Sep 17 00:00:00 2001 From: "William Hirigoyen (Evolix)" Date: Thu, 23 Dec 2021 15:51:55 +0100 Subject: [PATCH] =?UTF-8?q?#62716=20:=20Corrections=20et=20am=C3=A9liorati?= =?UTF-8?q?ons=20ftpadmin.sh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/ftpadmin.sh | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/scripts/ftpadmin.sh b/scripts/ftpadmin.sh index 064a00f..bc71876 100755 --- a/scripts/ftpadmin.sh +++ b/scripts/ftpadmin.sh @@ -59,30 +59,32 @@ log_msg() { get_user_login_by_UID() { uid=$1 - grep "$uid" /etc/passwd | awk -F : "{if (\$3==$uid) print \$1}" + grep "$uid" /etc/passwd | awk -F : '{if ($3==$uid) print $1}' } list_accounts_by_UID() { - uid=$1 + uid=$1 + + # Remove # and empty lines + ftp_users=$(grep -v -E '^[[:blank:]]*(#.*)*$' "$VPASSWD_PATH") - while IFS=$'\n' read -r line; - do - line_uid="$(echo "$line" | cut -d":" -f3)" - - if [[ ! "$uid" ]] || [[ "$line_uid" == "$uid" ]]; then - username="$(get_user_login_by_UID "$line_uid")" - account="$(echo "$line" | cut -d":" -f1)" - path="$(echo "$line" | cut -d":" -f6)" - size="$(du -s "$path" | cut -f 1)" - #modif="$(cat $path/.lastmodified)" - # Passage en minuscule ? - #account="$(echo $account | tr '[A-Z]' '[a-z]')" - #path="$(echo $path | tr '[A-Z]' '[a-z]')" - - echo "$username:$account:$path:$size${modif:+:$modif}" - - fi - done < "$VPASSWD_PATH" + for line in $ftp_users; do + line_uid="$(echo "$line" | cut -d":" -f3)" + + if [[ ! "$uid" ]] || [[ "$line_uid" == "$uid" ]]; then + username=$(get_user_login_by_UID "$line_uid") + account=$(echo "$line" | cut -d":" -f1) + path=$(echo "$line" | cut -d":" -f6) + size="inconnue" + # Check output of daily "du" cron job + # (set by ansible-roles/packweb-apache/tasks/main.yml) + if [ -r "$path/.size" ]; then + size=$(cat "$path/.size") + fi + #modif="$(cat $path/.lastmodified)" + echo "$username:$account:$path:$size${modif:+:$modif}" + fi + done } add_account() {