Ich schreibe ein Skript, um GID größer als 1000 und GID kleiner oder gleich 1000 zu filtern. Zweck ist es, lokale Gruppen und nicht-lokale Gruppen (Gruppen aus AD) aus filtern eine Datei ..Bash Script: While-Schleife und wenn Statement
Es gibt eine Datei namens groups.out, die Gruppennamen und GIDs enthält. Es könnte in beliebiger Reihenfolge sein. Unten ist die Beispieldatei, die lokale Gruppen, nicht = lokale Gruppen und GIDs enthält.
1098052
1098051
domain users
fuse
gdm
haldaemon
und hier ist die Logik I
Read line by line from the file,
if the line is a number then check
if number greater than or equal to 1000 then check
if greater than or equal to 1000, append it to the file
else if number less than 1000 then dump it
else if erorr occurs append error to file and break the loop and exit
if the line is a string then check the gid of the string/group
if number greater than or equal to 1000 then append to file
else if gid less than 1000 then dump it
else if error occurs append error to file and break the loop and exit
want to repeat it in the loop line by line and if anywhere the error occurs loop should break and exit the entire script
Nach erfolgreicher Ausführung der Schleife sollte es Erfolg drucken oder wenn ein Fehler auftritt angewendet werden soll, sollte es beenden und fügen Fehler in die Datei. Unten ist mein ungekochter Code mit vielen fehlenden Teilen. Viele Fehler sind auch für GT- oder EQ-Fehler vorhanden. so können Sie es
fileA="groups.out"
value=1000
re='[a-z]'
num='[0-9]'
while IFS= read lineA
do
group=$(getent group "$lineA" | awk -F: '{print $3}')
# ------Don't know how to check if a number or string -----
if [ "$group" -gt "$value" ]; then
echo "$lineA" >> ldapgroups.out 2>> error.out
elif [ "$group" -lt "$value" ]; then
echo "$lineA" >> /dev/null 2>> error.out
else
echo " FAILED"
exit 1
fi
hier ist eine mögliche lösung zu überprüfen, ob nummer oder string in bash http://stackoverflow.com/a/806923/524743 – Samuel