LQ Newbie
Registered: Mar 2008
Location: Michigan
Distribution: RHEL 5.4 / Ubuntu 9.10
Posts: 8
Rep:
|
Having a problem getting my shell script to send an email after each row.
I am using grep and also cut to dissect a file that contains this sample text.
Route,# of Stops,
DistpatchTime,ReturnTime,Miles,Cases,Backhaul,Driver,Email addresss alias
364,4,02:00 Wed,11:48 Wed,94,729,0,SMITH,33229
365,4,20:30 Tue,06:33 Wed,148,1270,0,BRADNER,33277
366,4,01:30 Wed,13:10 Wed,65,1211,0,BEACH,81234
I am ignoring the header field descriptions and concentrating on each of the three lines below it.
My goal here is to extract "each" comma separated value in each row, echo it out into a body of text and send a separate email using the mail command. The last field in each row represents an email alias that I plan on appending an email domain to. Essentially each line will be a separate email going to whomever.
My script works perfectly fine if I only have one row inside the text file.
I am really new at this stuff honestly.
This is what I have thus far. Any help would be very appreciated!
#!/bin/bash -vx
dos2unix /home/chiptransfer/Route.cvs
grep -v 'Route' Route.cvs 2>&1 | cut -f1,2,3,4,5,6,7,8,9 -d',' 2>&1 | sed -e 's/Wed/Wednesday/g' -e 's/Tue/Tuesday/g' >/home/chiptransfer/Step1.txt
dos2unix /home/chiptransfer/Step1.txt
ROUTE="$(cut -f1 -d',' /home/chiptransfer/Step1.txt)"
STOPNUMBERS="$(cut -f2 -d',' /home/chiptransfer/Step1.txt)"
DISPATCHTIME="$(cut -f3 -d',' /home/chiptransfer/Step1.txt)"
RETURNTIME="$(cut -f4 -d',' /home/chiptransfer/Step1.txt)"
MILES="$(cut -f5 -d',' /home/chiptransfer/Step1.txt)"
CASES="$(cut -f6 -d',' /home/chiptransfer/Step1.txt)"
BACKHAUL="$(cut -f7 -d',' /home/chiptransfer/Step1.txt)"
DRIVER="$(cut -f8 -d',' /home/chiptransfer/Step1.txt)"
MAILBOXID="$(cut -f9 -d',' /home/chiptransfer/Step1.txt)"
SMTP=@voicmail.keyfob.com
FULLEMAIL=$MAILBOXID$SMTP
if [ "$ROUTE" != "0" ]; then
echo " Hello Mr. $DRIVER. I am here to inform you of your scheduled rowte information for rowte number $ROUTE. Your Rowte number $ROUTE consists of $STOPNUMBERS stop numbers departing at $DISPATCHTIME and returning at approximately $RETURNTIME. The number of miles for this trip equals a grand total of $MILES miles and consisting of a total case count of $CASES. Thank you and have a pleasant trip to and from your destination Mr. $DRIVER." | mail -s "Rowte Information" $FULLEMAIL
fi
done
|