#!/bin/bash
# プライマリグループ名を取得するための辞書を作成します。
declare -A primary_group
while IFS=: read -r user pass uid gid rest; do
primary_group["$user"]=$(getent group "$gid" | cut -d: -f1)
done </etc/passwd
# ユーザー情報とプライマリ・セカンダリグループを表示します。
while IFS=: read -r user pass uid gid gecos home shell; do
primary=${primary_group["$user"]}
secondary=$(id -Gn "$user" | tr ' ' '\n' | grep -v "^${primary}$" | paste -sd, -)
shadow_info=$(getent shadow "$user")
min=$(echo "$shadow_info" | cut -d: -f4)
max=$(echo "$shadow_info" | cut -d: -f5)
warn=$(echo "$shadow_info" | cut -d: -f6)
inactive=$(echo "$shadow_info" | cut -d: -f7)
password_hash=$(echo "$shadow_info" | cut -d: -f2)
echo "$user:$uid:$gid:$primary:$secondary:$home:$shell:$min:$max:$warn:$inactive:$password_hash"
done </etc/passwd | sort -t: -k2 -n
More than 1 year has passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme