Sponsored Content
Top Forums Shell Programming and Scripting Read a file, add some text and send an email Post 302793643 by Don Cragun on Friday 12th of April 2013 08:59:55 PM
Old 04-12-2013
Quote:
Originally Posted by karthikbhuvana
Hi,

If I am asking this question, you must have already figured out , that I am new to Unix, so here it goes

I was trying to read a file, add some user defined content to it and send out an email , I did find out a way to achieve this, but looking at the code, it looks a bit crude to me, can you guys point out a more efficient way of writing this?

Here is the my Input file id_list.txt
Code:
Bob
Marcus
Adam

And this is what I expect to be sent in the email
Code:
This is a test email 

This is an email to notify you that the following ID's are going to expire in 1 week 

Please change the password for "Bob" to avoid being locked out.

Please change the password for "Marcus" to avoid being locked out.

Please Change the Password for "Adam" to avoid being locked out.

And this is what I wrote
Code:
EMAIL_TEXT1="This is a test email"
EMAIL_TEXT2="This is an email to notify you that the following ID's are going to expire in 1 week"
echo 
{
echo $EMAIL_TEXT1 $EMAIL_TEXT2
{
while read userID;
 do 
 { echo -n " Please change the password for " && echo -n \"$userID\" && echo " to avoid being locked out.\n"; }
done < id_list.txt
} }> final_op.txt
mutt -s "Test Email" "karthik@xyz.com" < final_op.txt

Can someone point out a better way to write this? Also can you also explain, instead of writing the file to the final_op.txt , if i pipe it to the mutt command, the email comes up in a non formatted way, that is the text inside the while loop comes up in a single line. But if i seperate it out it comes as I have mentioned in the expected output .

Thanks,
Karthik
Try:
Code:
EMAIL_TEXT1='This is a test email'
EMAIL_TEXT2="This is an email to notify you that the following ID's are going to expire in 1 week" 
( printf "%s\n\n%s\n" "$EMAIL_TEXT1" "$EMAIL_TEXT2"
  while read userID
  do    printf "\nPlease change the password for \"%s\" to avoid being locked out.\n" "$userID"
  done < id_list.txt
) | mutt -s 'Test Email' 'karthik@xyz.com'

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

script to send a file in email

a file is created on a daily basis in the name xyz_pqr_20071207.dat.i want to send the file as an attachment if the file contains more than 50 records.how can i write a script such that it will transmit the file after the file is created.i want to sed the file to say asdf@xyz.com. please help me... (2 Replies)
Discussion started by: dr46014
2 Replies

2. UNIX for Dummies Questions & Answers

How to send email attachment as read only in Linux

Hi, Could anyone help me to find soultion for the issue to send email attachment as read only. I can change the file permission in Linux and can send the email attachment from Linux. But my requirment is user can read the attachment but should not modified it . even user save the attachment... (4 Replies)
Discussion started by: calagar
4 Replies

3. Shell Programming and Scripting

Script to send email after comparing the folder permissions to a certain permission & send email

Hello , I am trying to write a unix shell script to compare folder permission to say drwxr-x-wx and then send an email to my id in case the folders don't have the drwxr-x-wx permissions set for them . I have been trying to come up with a script for few days now , pls help me:( (2 Replies)
Discussion started by: nairshar
2 Replies

4. Shell Programming and Scripting

How to read specific line of text from a Script and send email notification

Hi ! I am a newbie and never officially wrote a shell script before. The requirement for this script is : 1) Read a file called 'bpm.log' and identify if it has a specific text such as 'this is the text'. Its a static value and that is the only text we need to read. 2) If that... (2 Replies)
Discussion started by: atechcorp
2 Replies

5. Cybersecurity

How can you send a file over Ip.NOT EMAIL

So I was just wondering... Is there a way to send a file directly to the computer..... Ive never gotten the answer and I want to know how, I keep running in to a wall :wall:. Why you may ask, well really for security reasons due to the fact that if this is done via a port I want to make sure to... (3 Replies)
Discussion started by: orszhak
3 Replies

6. Shell Programming and Scripting

Script to read file size and send email only if size > 0.

Hi Experts, I have a script like $ORACLE_HOME/bin/sqlplus username/password # << ENDSQL set pagesize 0 trim on feedback off verify off echo off newp none timing off set serveroutput on set heading off spool Schemaerrtmp.txt select ' TIMESTAMP COMPUTER NAME ... (5 Replies)
Discussion started by: welldone
5 Replies

7. UNIX for Dummies Questions & Answers

send an email from batch file

My batch files run every day, it moves files from servers to my local computer, can I have a confirmation email sent to me from this batch file saying if the job failed or successes? Thank you for your help! (6 Replies)
Discussion started by: idiazza
6 Replies

8. Shell Programming and Scripting

Read file and send email

I have a file like this. I need to ues this file to send emails to the appropriate ID/group. For instance in the first line - Subject should be --> "A1.csv - ABC" - Body should be --> File A1.csv has changed. - Email should be sent to A1@xyz.com,A3@xyz.com Lookup.csv: ... (1 Reply)
Discussion started by: vskr72
1 Replies

9. UNIX for Beginners Questions & Answers

Merge Text with space into once cell and send email out

Please help!! This code works perfect but the only problem I am having is that is treats eg SQL Developer as separate cell/column which makes the formatting bad. I want to put SQL Developer in one cell. I attached a sample of how the output looks like. report.txt USERNAME OSUSER ... (5 Replies)
Discussion started by: lpoolfc
5 Replies

10. UNIX for Beginners Questions & Answers

Shell Script to read hive table and send email

HI Team, I am working on reading hive table and send email in email body using shell script, can you please help on fixing the errors: I have 6 columns in my hive table and trying to send the email in the mail body. below script: #!/bin/bash hive -e 'SELECT count(*) from db.table' >... (4 Replies)
Discussion started by: Mi4304
4 Replies
SCRIPT-EMAIL(8) 					  System Administration Commands					   SCRIPT-EMAIL(8)

NAME
script-email - Amanda script to send email notifications DESCRIPTION
script-email is an Amanda script implementing the Script API. It should not be run by users directly. It sends a notification email to the addresses specified in the MAILTO property. PROPERTIES
This section lists the properties that control script-email's functionality. See amanda-scripts(7) for information on the Script API, script configuration. MAILTO List of email addresses that will receive an email on command execution. It is a multi-valued property: property "MAILTO" "amanda@domain.com" "sysadmin@domain.com" "amandauser@domain.com" EXAMPLE
In this example, script-email is scheduled to be run before the DLE, on the server. The unqualified email address amanda will be passed to the email system unchanged. The script is then attached to a dumptype, which can then be specified for any DLEs which require notification. define script-tool pre-email { comment "email me before this DLE is backed up" plugin "script-email" execute-on pre-dle-backup execute-where server property "mailto" "amanda" } define dumptype user-tar-email { user-tar script "pre-email" } SEE ALSO
amanda(8), amanda.conf(5), amanda-client.conf(5), amanda-scripts(7) The Amanda Wiki: : http://wiki.zmanda.com/ AUTHORS
Jean-Louis Martineau <martineau@zmanda.com> Zmanda, Inc. (http://www.zmanda.com) Dustin J. Mitchell <dustin@zmanda.com> Zmanda, Inc. (http://www.zmanda.com) Amanda 3.3.3 01/10/2013 SCRIPT-EMAIL(8)
All times are GMT -4. The time now is 07:26 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy