#!/bin/bash
# This tells you that the script must be run by root.
if [ "$(id -u)" != "0" ];
then
echo "This script must be run as root!" 1>&2
exit 1
fi
userexists=0
while [ $userexists -eq 0 ]
do
# This asks for the user's input for a username.
echo -n "Enter a username: "
read username
x="$username:x:"
# This if block checks if the username exists.
grep -i $x /etc/passwd > /dev/null
if [ $? -eq 0 ]
then
userexists=1
else
echo "That user does not exist!"
fi
done
# This is the heading for the information to be displayed
echo "Information for" $username
echo "--------------------------------------------------------------------"
awk -v varname="var" -f passwd.awk /etc/passwd
awk -f shadow.awk /etc/shadow
BEGIN { FS = ":" }
/"variable"/{print "Username\t\t\t" $1
print "Password\t\t\tSet in /etc/shadow"
print "User ID\t\t\t\t"$3
print "Group ID\t\t\t"$4
print "Full Name\t\t\t"$5
print "Home Directory\t\t\t"$6
print "Shell\t\t\t\t"$7
}
シェルスクリプトから取得した変数を使用して awk スクリプトに入れて、特定のユーザーの passwd ファイルを検索し、その情報を表示する必要がありますが、それがどのように機能するかはわかりません。-v コマンドの使用方法と awk スクリプトのどこに配置するかが完全にはわかりません。