From 2668559dbcc38551d010258b3b6f60c6acccf537 Mon Sep 17 00:00:00 2001 From: Douglas Barone Date: Tue, 28 Feb 2023 15:11:34 -0400 Subject: [PATCH] Added bulk reset --- pdc-bulk-reset-password.sh | 44 ++++++++++++++++++++++++++++++++++++++ pdc-reset-password.sh | 3 ++- 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100755 pdc-bulk-reset-password.sh diff --git a/pdc-bulk-reset-password.sh b/pdc-bulk-reset-password.sh new file mode 100755 index 0000000..a65c09a --- /dev/null +++ b/pdc-bulk-reset-password.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +file=$1 + +DEFAULT_PASSWORD=123456789 +PASSWORD=${2:-$DEFAULT_PASSWORD} + +# Check if arguments are not empty +if [ -z "$file" ]; then + echo "Usage: $0 " + exit 1 +fi + +# Check if file exists +if [ ! -f "$file" ]; then + echo "File $file does not exist" + exit 1 +fi + +# Check if file is empty +if [ ! -s "$file" ]; then + echo "File $file is empty" + exit 1 +fi + +while IFS="" read -r p || [ -n "$p" ]; do + echo "---" + USERNAME=$(echo $p | cut -d ";" -f 1) + + # Check if $USERNAME is empty + if [ -z "$USERNAME" ]; then + echo "Username is empty" + continue + fi + + # Check if user exists + if ! samba-tool user show $USERNAME >/dev/null 2>&1; then + echo "User $USERNAME do not exists" + continue + fi + + ./pdc-reset-password.sh $USERNAME $PASSWORD + +done <$file diff --git a/pdc-reset-password.sh b/pdc-reset-password.sh index dd42c96..33b572b 100755 --- a/pdc-reset-password.sh +++ b/pdc-reset-password.sh @@ -1,7 +1,8 @@ #!/bin/bash USERNAME=$1 -PASSWORD=123456789 +DEFAULT_PASSWORD=123456789 +PASSWORD=${2:-$DEFAULT_PASSWORD} # Check if arguments are not empty if [ -z "$USERNAME" ]; then