Sponsored Content
Homework and Emergencies Homework & Coursework Questions script to mail users on comand line Post 302572740 by alis on Thursday 10th of November 2011 11:16:04 PM
Old 11-11-2011
script to mail users on comand line

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

1. The problem statement, all variables and given/known data:

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.

PLEASE ONLY SEND THIS MESSAGE TO USERS WHICH YOU KNOW PERSONALLY.

You can always use yourself and me as a test case.
The real name of the user of the script should only be computed once.
A "Here-Document (In-Line Redirection)" should be used for the mail message. No temporary files should be used.
The message should be as follows:
Hello "INSERT THE USERS REAL NAME FROM THE PASSWORD FILE",
Please ignore this mail. My instructor requires that I send this message as part of an assignment. The current time and date is . Have a nice day.
"insert the real name of the person running the script - do not hard code the value"


2. Relevant commands, code, scripts, algorithms:
sed, if-loop, ./user


3. The attempts at a solution (include all code and scripts):

Code:
#!/bin/bash

#Assignment 4 - Mail Users

if who | sed 's/ .*//g' | sort -u | grep "$*" > /dev/null
then
echo "$*" is logged in
else
echo "$*" not logged in
fi
if [ "$*" -eq 0 ]
then
echo no user specified
fi

mail "$*" << message
Hello `awk -F\: '{print $5}' /etc/passwd` please ignore this mail. My instructor requires that I send this message as part of an assignment for class 92.312. The current time and date is `date`. Have a nice day `$USER`.

END

4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
Umass-lowell, Lowell, Massachussetts. Mrichard. Unix shell programing.

Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Testing a comand in the script

Hi everyone , i am new to shell scripting and am having some problem to test if this line has been executed well and display a pass message on the screen or fail if not sqlplus XXTEST/$2 <<END > $XXTEST_TOP/log/$0.log @$XXTEST_TOP/admin/sql/XXTEST_SPE1_XX_QUOTE_DETAILS_TBL.sql XXTEST$2... (2 Replies)
Discussion started by: Lutchumaya
2 Replies

2. AIX

Command line/Script to send E-mail with HTML body and binary attachment

I apoligize for the cross-post but I'm not getting much in the way of help in the dummies forum: I'm trying to script sending an e-mail message on an AIX 5.x server with the following requirements: 1. command line switch to specify file name containing message body in HTML format 2. command... (3 Replies)
Discussion started by: G-Man
3 Replies

3. Ubuntu

script for memory monitoring and sending mail to users in network

I m working on a script which monitors the disk usage and send a mail to the users if it reaches a limit of 90%. hlp me (2 Replies)
Discussion started by: navdeep5673
2 Replies

4. Linux

Memory monitoring and sending alert mail to users in network using shell script

i m workiing on a shell script which may monitors network memory and send alert to user if it increase a threshold (1 Reply)
Discussion started by: navdeep5673
1 Replies

5. Shell Programming and Scripting

Send e-mail to users

Dear all, The perl script to send e-mail is working in my current script. #This part of the script will send the email notification my $to='mohamed.rahman@noridian.com'; my $from='xyz@hotmail.com'; my $subject='POS_CODES_38 DATA LOADED SUCCESSFULLY.'; my $message='The total no. of files... (2 Replies)
Discussion started by: msrahman
2 Replies

6. Shell Programming and Scripting

Mail to a file of users

How can I send the same form email to multiple users, but with variances like their username, password, and login host or environment? At work we use vdi's which are extremely slow - especially opening Outlook to open a form letter saved on Sharepoint. I was wondering if I could put the users'... (2 Replies)
Discussion started by: MaindotC
2 Replies

7. Shell Programming and Scripting

How to get users history as mail..

Hi all, Thanks in Advance, i want to view my users commands, what commands they are using in their terminal like that, how to automate this history process daily. (6 Replies)
Discussion started by: anishkumarv
6 Replies

8. Shell Programming and Scripting

Preserve extented ascii character when run echo comand inside bash script

Hi everyone, I'm echo some text with extended ascii characters as below: echo -e "Pr\xE9sentation du spectacle" > output or echo -e "Présentation du spectacle" > outputIf I open the file created I see this text Présentation du spectacleThe text is shown correctly in this created file when... (7 Replies)
Discussion started by: Ophiuchus
7 Replies

9. Shell Programming and Scripting

Need comand or script for append text after searching for the desired string

Hi all, i have a generated report in unix in the following command like input.txt 47.85,10 0124,42.35,8 0125,3.5,2 the input file format is fixed I need the my output file with append text as below output.txt 0124 amount:42.35 0125 amount:3.5 0124 count : 8 0125... (34 Replies)
Discussion started by: hemanthsaikumar
34 Replies

10. UNIX for Beginners Questions & Answers

How to write a UNIX script to send a mail to the respective individual users about their groups?

Hi Team, I got a requirement to send a mail to the individual users of a unix server about their respective groups. can some one help me to provide the script as I am unable to write that. I tried with below lines but I come out with errors. cat /etc/passwd | awk -F':' '{ print $1}' |... (6 Replies)
Discussion started by: harshabag
6 Replies
LOGIN(1)						      General Commands Manual							  LOGIN(1)

NAME
login - sign on SYNOPSIS
login [ username ] DESCRIPTION
The login command is used when a user initially signs on, or it may be used at any time to change from one user to another. The latter case is the one summarized above and described here. See `How to Get Started' for how to dial up initially. If login is invoked without an argument, it asks for a user name, and, if appropriate, a password. Echoing is turned off (if possible) during the typing of the password, so it will not appear on the written record of the session. After a successful login, accounting files are updated and the user is informed of the existence of .mail and message-of-the-day files. Login initializes the user and group IDs and the working directory, then executes a command interpreter (usually sh(1)) according to speci- fications found in a password file. Argument 0 of the command interpreter is `-sh. Login is recognized by sh(1) and executed directly (without forking). FILES
/etc/utmp accounting /usr/adm/wtmp accounting /usr/mail/* mail /etc/motd message-of-the-day /etc/passwd password file SEE ALSO
init(8), newgrp(1), getty(8), mail(1), passwd(1), passwd(5) DIAGNOSTICS
`Login incorrect,' if the name or the password is bad. `No Shell', `cannot open password file', `no directory': consult a programming counselor. LOGIN(1)
All times are GMT -4. The time now is 08:00 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy