Automating Mail Process


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Automating Mail Process
# 8  
Old 07-29-2016
Automating Mail Process

Hi rbatte1
U r correct.i should be more specific.at present this script can send max 2 attachment at a time.but issue here is we can not modify the script all time.once we give it to our boss,he can not changes again and again.Before submitting the script we should make it proper. So script should automatically ask user these many files are available under this particular Folder and which all file you want to attach them with mail.e.g.
  1. 1st list all the attachment with serial#.
  2. Then user should enter i want from 2-5 and 6-8.
  3. Finally these name should be attached in script

Last edited by rbatte1; 07-29-2016 at 10:23 AM.. Reason: Changed text numbered list to formatted numbered list
# 9  
Old 07-29-2016
If you want to magically guess at which files in your Desktop directory are intended to be attachments, it won't be easy (unless you can explain and implement the magic). If you are willing to move all of the files that you want to be treated as attachments into a directory in your Desktop directory (in the following example, that directory is named attachments), you might want to try something like:
Code:
#!/bin/bash
ATTACHMENT_DIR="/home/sreenivasa/Desktop/attachments"
ATTACHMENTS=
BODY_FILE="/home/sreenivasa/Desktop/Testing.txt"
SUBJECT="linux mail send attachment example"
TO_LIST="rajnikant875@gmail.com,sinha6315@gmail.com,rajnikant@gytechs.com"

# Gather list of attachments:
for file in "$ATTACHMENT_DIR"/*
do	[ ! -f "$file" ] && continue
	ATTACHMENTS="$ATTACHMENTS -a \"$file\""
done

# Send the message.
mail -s "$SUBJECT" "$ATTACHMENTS" "$TO_LIST" < "$BODY_FILE

Note that the text marked in red above serves two purposes:
  1. it only selects regular files from that directory to be used as attachments, and
  2. it keeps an error from occurring in the mail command if that directory doesn't exist or is an empty directory.
Note also that I renamed the variable CC_LIST to TO_LIST because the e-mail addresses in that list will be on the To: list in the mail message that is sent; not on that message's Cc: list.
These 2 Users Gave Thanks to Don Cragun For This Post:
# 10  
Old 07-29-2016
Automating Mail Process

Thanks Don Cragun for quick reply.
i am trying to run this script but it is unable to attach any kind of files from that particular folder.it is sending mail but without any attachment.
My requirement is like, script should attach all files from that particular folder.
One thing i did not understand what is use of variable ATTACHMENTS and file.

Can u please brief me.

Thank u
Rajnikant
# 11  
Old 07-29-2016
In the manual page for mail on your server, do you have the -a flag? (not the same as the -A flag)

If not, then this will not work.





Robin
# 12  
Old 07-29-2016
Quote:
Originally Posted by rbatte1
In the manual page for mail on your server, do you have the -a flag? (not the same as the -A flag)

If not, then this will not work.





Robin
Hi Robin,
Note that Rajnikant said that the script in post #1 in this thread was working to send mail with a single attachment (using the mail -a option). I don't know of any versions of mail that accepts a -a option that won't accept multiple -a options.
Quote:
Originally Posted by rajnikant
Thanks Don Cragun for quick reply.
i am trying to run this script but it is unable to attach any kind of files from that particular folder.it is sending mail but without any attachment.
My requirement is like, script should attach all files from that particular folder.
One thing i did not understand what is use of variable ATTACHMENTS and file.

Can u please brief me.

Thank u
Rajnikant
Hi Rajnikant,
The for loop in my script executes the commands inside the loop once for each file in the directory /home/sreenivasa/Desktop/attachments. Each time it executes the commands in that loop, the shell variable file will be set to the name of one of the files in that directory. For every regular file it finds in that folder it adds -a and the name of that file (in quotes) to the shell variable ATTACHMENTS which is then used in the mail command to include those files as attachments to the message it sends.

To avoid sending unwanted mail while we are testing, please change:
Code:
mail

on the last line of your script to:
Code:
echo mail

Then show us the output you get from running the commands:
Code:
ls -l /home/sreenivasa/Desktop/attachments
     and
od -bc < your_script_name
     and
bash -xv your_script_name

where your_script_name is the name of the file containing your script.
This User Gave Thanks to Don Cragun For This Post:
# 13  
Old 07-31-2016
Automating Mail Process

Hi Don Cragun
u asked me to run the script and few commands.i ran it and attached it with this message.please have a look at Attach Files.

Thank U
Rajnikant
# 14  
Old 07-31-2016
Quote:
Originally Posted by rajnikant
Hi Don Cragun
u asked me to run the script and few commands.i ran it and attached it with this message.please have a look at Attach Files.

Thank U
Rajnikant
Hi Rajnikant,
In the future, when we ask for the output you get from running a command; please show us the output as text as it appears on your screen (presumably in a fixed width font as provided by CODE tags in the body of the post), not a Microsoft Word document given as an attachment using a variable width font and adding unwanted page breaks that hides much of the clarity in the output we need to see to help you.

I suggested that you should have:
Code:
mail -s "$SUBJECT" "$ATTACHMENTS" "$TO_LIST" < "$BODY_FILE"

as the last line of your script. Instead of that line, you used:
Code:
mail -s "$SUBJECT" "$ATTACHMENTS_DIR" "$TO_LIST" < "$BODY_FILE"

The trace from running your script clearly shows that it correctly set the variable ATTACHMENTS to include eight attachments, but you didn't expand that list in your invocation of mail. Instead you expanded the variable ATTACMENTS_DIR (which is never defined by your script and, therefore, expands to an empty string throwing away all of the work the script did to get your desired attachments).
This User Gave Thanks to Don Cragun For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Automating an interactive process with EOF string

Hello, I'm running Stockfish chess engine ( Home - Stockfish - Open Source Chess Engine ) CLI on Linux in interactive mode which is working fine. root@ubuntu1950x:~# ./stockfish Stockfish 080218 64 POPCNT by T. Romstad, M. Costalba, J. Kiiski, G. Linscott setoption name Debug Log File... (2 Replies)
Discussion started by: prvnrk
2 Replies

2. UNIX for Dummies Questions & Answers

Automating a process

Could any one tell me , how to start a thread here, i just searching for so long. sorry to post in irrelavent here ---------- Post updated at 08:19 AM ---------- Previous update was at 08:00 AM ---------- Hi, I got a requirement to automate the process. We have SLA files, there are... (1 Reply)
Discussion started by: afahmed
1 Replies

3. Shell Programming and Scripting

Automating The process

Hi Guru's, I am trying to write a scripts that will automate my image provisoining process. Scenario: I have Linux Image Hosted on cloud which needs to be provisoned before it can be used. Currently we log onto the image through the putty on windows and connect to linux instance. I... (3 Replies)
Discussion started by: taqvia
3 Replies

4. Shell Programming and Scripting

automating daily monitoring process

Hi there, I have to automate daily monitoring process and then the result of these process should be sent to a log file, then this log file should be mailed . ps -ef | grep aa In this atleast one process should run. If the process is running it should mention Success in the log file... (3 Replies)
Discussion started by: NehaKrish
3 Replies

5. Shell Programming and Scripting

script to monitor process running on server and posting a mail if any process is dead

Hello all, I would be happy if any one could help me with a shell script that would determine all the processes running on a Unix server and post a mail if any of the process is not running or aborted. Thanks in advance Regards, pradeep kulkarni. :mad: (13 Replies)
Discussion started by: pradeepmacha
13 Replies

6. Shell Programming and Scripting

Issue in mail sending process

Hi I created one CSV file and i need to append some message in the content of my mail. $sales=sales.dat $sales_csv=sales.csv $sales_report=sales.txt this is the command am using it. echo "sales for `date`"| read subject uuencode $sales $sales_csv | mailx -ms "${subject}."... (2 Replies)
Discussion started by: bobprabhu
2 Replies

7. Shell Programming and Scripting

Killing of a process and send a mail if the process doesnot come up within 2 minutes

Hi Friends, I am new to this forum as well as new to shell scripting. I have a problem here and i need someone to solve this. Let us consider there are two processes(abc & def).There is a script which kills these two processes(i.e killtheprocess abc). Here abc is the argument . There is a... (1 Reply)
Discussion started by: Prince89
1 Replies

8. Linux

Automating build and test process

Hey ppl, I've been asked to automate the build and test process for my team at office.we work on Linux and use Perforce for SCM. I've just joined this company and dont have much knowledge on unix scripts. Could someone tell me how to go about doing this?:confused: (8 Replies)
Discussion started by: laxmi
8 Replies

9. Shell Programming and Scripting

Automating build and test process

Hey ppl, I've been asked to automate the build and test process for my team at office.we work on Linux and use Perforce for SCM. I've just joined this company and dont have much knowledge on unix scripts. Could someone tell me how to go about doing this? (0 Replies)
Discussion started by: laxmi
0 Replies

10. UNIX for Dummies Questions & Answers

Process mail using cron

I am looking for information on how to process mail using a cron job. The email server is a hosted ISP, so I simply have a POP connection to the mailbox. Specifically, I want to fire a cron job at {x} time and have pine, mail, mailx, or some other suitable mail client utility process the... (1 Reply)
Discussion started by: EOD
1 Replies
Login or Register to Ask a Question