
Linux(Ubuntu)의 사용자 목록에서 로그인한 모든 사용자를 어떻게 grep합니까?
지금까지 나는 다음을 수행했습니다.
cat /etc/passwd | grep "/home" | cut -d: -f1
답변1
위에 댓글을 달았거나 로그인한 사람이 누구인지 보여주는 사람..
lastlog를 보면 과거/현재 데이터를 볼 수도 있습니다.
마지막 잘못된 로그인에 대해서는 lastb를 사용합니다.
w|grep pts|awk '{print $1}'
for ids in $(w|grep pts|awk '{print $1"_"$2}'); do id=${ids%%_*}; pts=${ids##*_}; actualperson=$(getent passwd $id|awk '{print $5}'); echo "Username: $id is $actualperson and is logged into $pts"; done;
사용자 이름: xxx는 pts/0에 로그인되어 있습니다.
사용자 이름: xxx는 pts/5에 로그인되어 있습니다.
for ids in $(w|grep pts|awk '{print $1"_"$2}'); do
id=${ids%%_*};
pts=${ids##*_};
actualperson=$(getent passwd $id|awk '{print $5}');
# echo to your console the persons details
echo "Username: $id is $actualperson and is logged into $pts";
# Send a message to person logged in telling them you know their logged in
echo "I know your logged in $actualperson"|tee /dev/$pts 2>&1>/dev/null;
done;
답변2
명령 users
이 도움이 될 것입니다. 매뉴얼 페이지에서:
users - print the user names of users currently logged in to the current host