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, the full (real) name from the passwd file (/etc/passwd) should be used. Also, mail should be signed with the real name of the person who is running the script.
Following error message should be printed if an argument username does not exist in the passwd file - "Please send this message to users whom you know personally.".
The mail message should be as follows:
Hello "<INSERT THE ARGUMENT USER'S REAL NAME FROM THE PASSWORD FILE>",
Please ignore this mail. The current time and date is <CURRENT DATE AND TIME>. Have a nice day.
"<INSERT THE SCRIPT RUNNING USER'S REAL NAME FROM THE PASSWORD FILE>"
Attached file 151594.sh gives the required bash script.
Script is well commented ...
Script is well commented and does not use temporary files, but instead makes use of Here-Document (inline redirection) for the mail message. It also computes the real name of the person running the script only once, with the help of environment variable "USER" and the password file.