Shell-script - How to fetch user details form etc passwd file, Get user details in argument or variable
How to fetch user details form etc passwd file
Many of my friends have asked me how to fetch the user details in each variable or field? They have said its required to use according to their different use. Some had said it was necessary when the need to user name and user details of their server. And other requirement line to create a same userlist as same as the old server.while read line do user_name="$(echo $line | cut -d: -f1)" user_id="$(echo $line | cut -d: -f3)" user_details="$(echo $line | cut -d: -f5 )" user_dir="$(echo $line | cut -d: -f6 )" echo "User Name = $user_name" echo "User Id = $user_id" echo "User Details = $user_details" echo "User Home Directory = $user_dir" echo "--------------------------------------" done</etc/passwdIn the above script the /etc/passwd is passwd as the input file and each line is parsed using cut command and stored in the varilables. In later section we can see how to use these variables, you can use these variables for different use and which we will see other section.
Sample output:
User Name = rpc User Id = 32 User Details = Rpcbind Daemon User Home Directory = /var/lib/rpcbind -------------------------------------- User Name = rpcuser User Id = 29 User Details = RPC Service User User Home Directory = /var/lib/nfs -------------------------------------- User Name = nfsnobody User Id = 65534 User Details = Anonymous NFS User User Home Directory = /var/lib/nfs --------------------------------------
The topic on Shell-script - How to fetch user details form etc passwd file is posted by - Marc
Hope you have enjoyed, Shell-script - How to fetch user details form etc passwd fileThanks for your time