Complete this assignment on hills. Use a shell script to complete your homework. Makes sure that your resulting .sh file is readable.
uinfo.sh outputs a few pieces of information about a user's account. It takes a single argument - the login of the user about whom you want information. When it starts, it must ensure that it is given a single argument. If not, it must abort with a message (use one of the variable operators for this as you did in Lab2, or use an if statement). If the argument is valid, here is what your script does:
get the user's line from /etc/passwd using command substitution. Design a regular expression to extract the single line only (Try your RE for the user gboyd) Save the line in a variable.
If no such users exists, abort with a message. You can deduce whether or not a user exist by using grep which returns an empty message if no user exists. You can abort with a message by using the same type of variable operator as you used to see if uinfo was given an argument. Otherwise, continue with the shell script.
Output each of the following. The value of each piece of data must have some kind of quotes around it in the output for emphasis.
the login id
where the user's home directory is (from the passwd line you just extracted)
what shell they use (from the passwd line you just extracted)
the user's real name (see below)
the permissions of the user's home directory as output in an ls -l listing.
You must output all of this information without running grep on the passwd file more than once. Extract the line for the user, save it in a variable, and use the variable to extract the pieces you need.
Each of these should be output in complete sentences.
$ ./uinfo.sh joe Information about the user "joe" follows: Home directory is "/users/joe" Shell is "/usr/bin/ksh" Real name is "Joe Blow" $ ./uinfo.sh joe1 ./uinfo.sh: line 5: user: no such user $ ./uinfo.sh ./uinfo.sh: line 2: user: need a single argument
The passwd file contains 7 fields delimited by colons. The fifth field may have subfields delimited by commas. This field is used by the program finger, and, hence, is called the finger information field (or, by the old name, the GECOS field). The first comma-separated field here is the user's real name. To see how this works, examine the passwd entry for me, gboyd, on hills. To enter your own real name (which could be your name or a title), run the program chfn on hills.
To submit your work, upload a copy of your uinfo.sh file to Canvas. Any analysis of your script should be copied and pasted into the Lab 3 Textbox