Sending files to multiple emails

Hi All,

I want to send each file to each email id as below.
Instead of writing saparate 10 mail commands
can we do it in a simple step.

file1.csv to raghu.s@hps.com
file2.csv to kiran.m@hps.com
file3.csv to kenni.d@hps.com
file4.csv to rani.d@hps.com
file5.csv to sandya.s@hps.com
file6.csv to kartik.a@hps.com
file7.csv to samul.c@hps.com
file8.csv to hegde.b@hps.com
file9.csv to krishna.h@hps.com
file10.csv to ramya.v@hps.com

Please help me.

Thanks,

I would actually use 2 arrays in the event the files aren't sequential. I don't know that you are really saving anything by shorting the number of lines.

Here something to consider...

#! /bin/bash
arr=(ragu.s kiran.m keeni.d rani.d sandya.s kartik.a samul.c hedge.b krishna.h ramya.v)
count=0
for i in ${arr[@]}
do
(( count++ ))
echo "Mail file${count}.csv to ${i}.hps.com"
done

Note: you would replace the echo statement with the correct system command for the mail command

i.e.

cat file.csv | mailx -s "subject" -u <user>

How about modifying your file slightly, e.g.

sed 's/^/</;s/ to / mail /' file
<file1.csv mail raghu.s@hps.com
<file2.csv mail kiran.m@hps.com
<file3.csv mail kenni.d@hps.com
<file4.csv mail rani.d@hps.com
<file5.csv mail sandya.s@hps.com
<file6.csv mail kartik.a@hps.com
<file7.csv mail samul.c@hps.com
<file8.csv mail hegde.b@hps.com
<file9.csv mail krishna.h@hps.com
<file10.csv mail ramya.v@hps.com

and then sourcing the result in your shell?

1 Like