Purchase Solution

Bash script: sending customized mail to specified users

Not what you're looking for?

Ask Custom 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, 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>"

Purchase this Solution

Solution Summary

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.

Solution Preview

Attached file 151594.sh gives the required bash script.

Script is well commented ...

Purchase this Solution


Free BrainMass Quizzes
Basic Networking Questions

This quiz consists of some basic networking questions.

Word 2010: Tables

Have you never worked with Tables in Word 2010? Maybe it has been a while since you have used a Table in Word and you need to brush up on your skills. Several keywords and popular options are discussed as you go through this quiz.

Inserting and deleting in a linked list

This quiz tests your understanding of how to insert and delete elements in a linked list. Understanding of the use of linked lists, and the related performance aspects, is an important fundamental skill of computer science data structures.

C++ Operators

This quiz tests a student's knowledge about C++ operators.

Java loops

This quiz checks your knowledge of for and while loops in Java. For and while loops are essential building blocks for all Java programs. Having a solid understanding of these constructs is critical for success in programming Java.