Explorar el Código

Clase Lunes 2017-10-30

Guzmán Castanedo Villalba hace 6 años
padre
commit
b7eb434595
Se han modificado 2 ficheros con 22 adiciones y 2 borrados
  1. 2 2
      listusers.sh
  2. 20 0
      listusers2.sh

+ 2 - 2
listusers.sh

@@ -14,7 +14,7 @@ while read linea; do
 	echo $linea | grep /usr/sbin/nologin >/dev/null
 	if [ $? -ne 0 ]; then
 		uid=$(echo "$linea" | cut -d: -f1)
-		gid=$(echo "$linea" | cut -d: -f3)
-		echo -e "uid: $uid\tgid: $(id -gn $gid)"
+		gid=$(echo "$linea" | cut -d: -f4)
+		echo -e "uid: $uid\tgid: $(id -gn $uid)($gid)"
 	fi
 done < /etc/passwd

+ 20 - 0
listusers2.sh

@@ -0,0 +1,20 @@
+#!/bin/bash
+
+#Guardar IFS anterior
+#SAVEIFS=$IFS
+#IFS=$(echo -en "\n\b")
+#for linea in $(cat /etc/passwd); do
+#	echo "$linea"
+#done
+
+#Restauramos contexto
+#IFS=$SAVEIFS
+
+while read linea; do
+	uid=$(echo "$linea" | cut -d: -f1)
+	gid=$(echo "$linea" | cut -d: -f4)
+	shell=$(echo "$linea" | cut -d: -f 7)
+	if [ $shell != "/usr/sbin/nologin" ]; then
+		echo -e "uid: $uid\tgid: $(id -gn $uid)($gid)"
+	fi
+done < /etc/passwd