나는이 코드를 통해 사용자 계정 정보를 생성합니다. 문제는 사용자 이름을 입력하고 지정된 사용자 이름에 대한 정보 만 검색하는 사용자 이름 행이 있다는 것입니다. 코드는 시스템의 모든 사용자에 대한 정보를 검색합니다.리눅스에서 특정 사용자에 대한 정보 검색
#! /bin/bash
#This script returns import information about the user name on the system
echo "PLease enter name to continue:"
read SuppliedName
for user in $(cut -d: -f1 /etc/passwd)
#while [ "$SuppliedName" == "$USER" ]
do
IFS=$'\n'
userinfo=$(grep $user: /etc/passwd)
comment=$(echo $userinfo | cut -d: -f5)
home=$(echo $userinfo | cut -d: -f6)
groups=$(groups $user | cut -d: -f2)
#Skip users that do not have '/home' in the path to their home directory
if [ $(echo "$home" | grep -v '/home/') ]
then
continue
fi
echo "Username: $user"
echo "User Info: $comment"
echo "Home Directory: $home"
echo "Groups: $groups"
echo "Disk usage: $(du -sh $home)"
last=$(last $user | head -1)
if [ $(echo $last | wc -c) -gt 1 ]
then
echo "Last login: "
echo "$last"
else
echo "User has never logged in!"
fi
echo ""
echo "--"
echo ""
done
그것은 일이 여전히'grep'를 고정되지 않는 문제가 – cookiemonster