-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmb-missing-users.sh
39 lines (28 loc) · 1.26 KB
/
smb-missing-users.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/bash
#downloading files generated by the script samba_export_users.sh
ssh root@SAMBASERVER './samba-export-users.sh'
sleep 2
scp root@SAMBASERVER:/root/users-export/valid_users_clean.csv .
#exporting users from smb.conf file, this is raw and the 4 first lines needs to be deleted
#ssh files "grep -A 1 "valid users" /etc/samba/smb.conf | awk -F "=" '{print $2}' | sed 's/,/\n/g' | sed 's/ //g' | sort | uniq" > valid_users_raw.csv
#deleting the first 4 lines
#sed '1,4d' valid_users_raw.csv > valid_users_clean.csv
ldbsearch -H /var/lib/samba/private/sam.ldb | grep "sAMAccountName" | cut -d ":" -f 2 | sed 's/ //g' >> users-from-ad.csv
sleep 2
# Save the lines in file A as an array
lines_in_file_a=($(cat valid_users_clean.csv))
# Use a for loop to iterate through the lines in file A
for line in "${lines_in_file_a[@]}"; do
# Use grep to search for the current line in file B
if grep -q "$line" users-from-ad.csv; then
:
else
# If the line is not found in file B, print a message to the terminal
echo "$line"
fi
done > users-not-found.csv
sed -i '/@Domainadmins/d' users-not-found.csv
cat users-not-found.csv | mail -s "Samba users missing in AD" system@yourcompany.fr
#for i in $(cat users-not-found.csv); do
# sed -i "s/$i, //g" smb.conf
#done