Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a shell script to send a customized mail message to the users listed on th

ID: 3679239 • Letter: W

Question

Write a shell script to send a customized mail message to the users listed on the command line by login (user) name, only if they are currently logged on.

If no users are listed on the command line an error message should be printed.

In the mail message, you should use the full (real) name from the passwd file (/etc/passwd).

You also need to sign the script with the real name of the person who is running the script.

This can be derived from the $USER environment variable and looking up the value in the password file.

An error message should be printed if the user does not exist in the passwd file or in NIS (YP)

The password information on the server is stored in NIS (Yellow-Pages YP).

You can use ypmatch or ypcat passwd to get the information

On the server, the information is both in /etc/passwd or can be extracted in the manner listed above.

The real name of the user of the script should only be computed once.

Explanation / Answer

If there are no position parameters (usernames) listed on the command line then print an error message exit the script endif #cool, that I got, inshallah #get the real name of the user running the script #($USER) from field 5 of the password file #and remember that when you look in the password file #you must exactly match field 1 or if you are #using NIS, then you must exactly match the username #Also remember that you can get false positive matches #if you are not careful. For example #say you had these usernames maryjane, mary, and #maryann, and you were were looking for mary, if your #matching is not right, you may also match maryjane #and maryann for each username listed from positional parameters do if the username exists in the password file or NIS password (see note above about maching) then if the username is logged in (see not above about matching) then send the mail message else print a message that the username is not logged into the system endif else print a message that the username does not exist endif done

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote