script to mail user


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting script to mail user
# 1  
Old 11-08-2011
script to mail user

I am trying to write a script to send a customized mail message to the users listed on the command line by login name only if they are logged in. If no users are listed on the command line an error message is printed. In the mail message I use the users real name from /etc/passwd. I am trying to write the mail message using a here document.

This is what I have so far, but I am not getting what I should do at the beginning.
PLease help!

Code:
#!/bin/bash

until who | cut -c1-8 | sort -u | grep -w "$1" > /dev/null
do
if
#this is where I need help!
mail $USER << 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 `time` `date`.


Last edited by vgersh99; 11-08-2011 at 05:22 PM.. Reason: code tags, please!
# 2  
Old 11-08-2011
This sounds like a homework question.
I'm closing the thread. Please continue here adhering to the homework posting rules.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Is it possible to send mail to a UNIX user id ?

Hi , I am trying to know the possibility of sending a mail to my unix user id from my gmail. Is there any such possibility to send the same? Please reply. Thanks in advance. (2 Replies)
Discussion started by: ssk250
2 Replies

2. UNIX for Advanced & Expert Users

Mail not getting delivered to user

Hi, There is a unix box in production from which mails will be sent to user/group. From this box, many mails will be sent. But only for one mail which is sent from the box, it is showing a message like "Deferred: 421 Microsoft ESMTP MAIL Service, Version: 6.0.3790.4675 ready at Service not... (2 Replies)
Discussion started by: trichyselva
2 Replies

3. Debian

Forward a specific incoming mail to a user

Hi There Not sure if this is the correct place for this. I'm running Sendmail on a Debian box and want to do the following. e-mail comes in from userk@domain.co.za and is destined for usera@mydomain.co.za, but i want all mail from userk@domain.co.za to go to userb@mydomain.co.za. Sendmail... (3 Replies)
Discussion started by: linuxjunkie
3 Replies

4. Shell Programming and Scripting

script to read mail on a mail server

Hi All, Is there any way Unix shell script can directly read a mail on a mail server (for eg. abc@xyz.com) and save it as a text file in a unix directory ? Thanks PRKS ---------- Post updated at 08:37 AM ---------- Previous update was at 08:36 AM ---------- I am using ksh (1 Reply)
Discussion started by: PRKS
1 Replies

5. OS X (Apple)

Ho do I masquerade the "user@user.local" address in mail/mailx?

Hi, I'm brand new here and looking for a solution: I'm using mail or mailx. The default reply address is «myshortusername@mylongusername.local» which makes absolutely no sense for anybody receiving my emails. But how do I change it? There seem to be many solutions but none for Mac OS X.... (0 Replies)
Discussion started by: gczychi
0 Replies

6. Post Here to Contact Site Administrators and Moderators

e-mail sent to user about PERL

Is there a way to setup an e-mail job (thru my account) to send me e-mail every time a new question or response to PERL is entered into a forum? thanks, djehresmann (1 Reply)
Discussion started by: djehresmann
1 Replies

7. UNIX for Dummies Questions & Answers

New User/Mail setup question. PLEASE help.

OK, here's the situation. Our regular computer guy left the company without warning. We are in the process of replacing him with someone much more knowlegeable than I, but as of right now, I have been handed the duties. Our mail server is running OpenBSD and I need to set up a new employee with an... (3 Replies)
Discussion started by: Rotting
3 Replies

8. Shell Programming and Scripting

READING mail from /var/mail/user

Hello guys, I'm in desperate need. I need to write a script that behaves like a "mail" shell program. I've a base of the program -menu and so on, but what I cannot do is how to read messages from /var/mail/user. I would like to separate them as "mail" program does, but I;m just a newbie and... (21 Replies)
Discussion started by: petoSVK
21 Replies

9. UNIX for Dummies Questions & Answers

Send mail when user logs in.

Hi All, I have a specific requirement hope you guys can help me resolve this problem. I want to send an email when a specific user logs in.. Eg: My User ID on the Unix box is VENKYA when I log into the System can we send a mail that I logged in. I am on a Sun Solaris Server. ... (3 Replies)
Discussion started by: venkyA
3 Replies

10. Shell Programming and Scripting

how can I check the user's mail quota?

how can I check mail quota, and then how can I send mail to user whose quota get full??? :confused: For this which script must I use? (8 Replies)
Discussion started by: emreatlier
8 Replies
Login or Register to Ask a Question