I am trying to generate and send html files by attaching to email body. I tried using awk for generating and sending one file. eg. the input file MARTINI has these records:
1554894,2015-04-16,00:21:52,processes.martini_gsicorptradeeventoutput.instancecount,0,1,UP
1554793,2015-04-15,22:03:52,processes.martini_gsicorptradeeventoutput.instancecount,2,0,DOWN
and I have this awk in a file named HTML:
awk 'BEGIN {
FS=","
print "MIME-Version: 1.0"
print "To:lijo#abc.com"
print "From:lijo#abc.com"
print "Subject: Health check"
print "Content-Type: text/html"
print "Content-Disposition: inline"
print "<HTML>""<TABLE border="1"><TH>Ref_id</TH><TH>EOD</TH><TH>Time</TH><TH>Process</TH><TH>Desc</TH><TH>Instance</TH><TH>Status</TH>"
}
{
printf "`<TR>`"
for(i=1;i<=NF;i++)
printf "`<TD>%s</TD>`", $i
print "`</TR>`"
}
END {
print "`</TABLE></BODY></HTML>`"
} ' /home/martini > /home/martini_html
Later I send this file through email cat MARTINI_HTML | /usr/sbin/sendmail -t . This works until here. But now i have 2 new tasks
How to convert multiple files Say MARTINI1, MARTINI2 ... etc into html files and how to attach them in email body as separate table block and not as a single table. Assuming two files are attached then email body should look similar to the image attached.
Here's how to do it: cheat.
Send yourself an email with two attachments. Use that raw email as a template. That way you can skip all the discovery about MIME types and whatnot.
Related
I am calling a function in commonfuncs to send email as below:
#!/usr/bin/ksh
. commonfuncs
emailsend 'test mail' 'body of the mail' 'abc.efg#domain.com'
the function is as below:
function emailsend
{
esubject=$1
etext=$2
etolist=$3
efromid="from.id#domain.com"
echo $etext >email.txt
cat email.txt | mailx -r $efromid -s $esubject $etolist
}
The email is sent fine. But the subject is send only as test instead of test mail. Tried with double quotes too but no use.
Try to wrap with double quotes parameters of the malix command:
cat email.txt | mailx -r "$efromid" -s "$esubject" "$etolist"
because the space character is a delimiter of the command line arguemnts.
I am getting input data in file with "|" delimeter but some of records breaking and coming as two records . below is the example ,
for most of description fields data is coming like this only, actually these are entering through web when user press enter while adding comment it going to newline , can you please let me know how to handle this.
I want this record in single line,
"2016-03-03 22:26:20|0|I|NOT SET ||||||||||||||||2015-02-12-04.34.38.734657|2015-02-13| |0|METER FAILURE >30 DAYS"
" |259000-056608 |TRBLRPRT|BDMTRRPL| || |0||| "
echo "$yourdata" | tr -d '\r\n'
Or
cat filename.txt | tr -d '\r\n'
To update file:
datastr=$(cat filename.txt | tr -d '\r\n')
then
echo -n "$datastr" > filename.txt
Hope it helps
This substitutes a space for carriage returns or line feeds
cat test.txt | tr ["\n","\r"] ' '
I am trying to generate some report and send it through unix. This report contains PIE-charts any idea how to inline send charts in mail body.
I tried below code. HTML is working in browser but after I send the HTML over mail it does not shows anything in mail body.
`MAILTO="x#a.com"
FROM='y#x.com'
CONTENT="pi.html"
SUBJECT="test"
(
echo "To:$MAILTO"
echo "From:$FROM"
echo "Cc:$CC"
echo "Subject: $SUBJECT"
echo "MIME-Version: 1.0"
echo "Content-Type: text/html"
echo "Content-Disposition: inline"
cat $CONTENT
) | /usr/sbin/sendmail -t`
content of pi.html ( I have copied the content from the url and pasted in pi.html)
https://developers.google.com/chart/interactive/docs/gallery/piechart
Please suggest a way to handle this.
I know ARGV[i] can be used for storing user input. However, I want to use it in awk script and get the ARGV[i] to compare the field from another text file. If the ARGV[i] matches the field or the field contains ARGV[i] which is the user input, then I want to return the other fields of that line.
Let say I have a file, testing.txt
123123123:Walter White:1:2:3:4
123123124:Jesse Pinkman:1:3:4:1
This is my awk script, awkScript.awk
#!/usr/bin/awk -f
BEGIN{FS = ":"; print "ENTER A NAME: "}
{
for (i = 1; i < ARGC; i++)
{
if ($2 ~ /'ARGV[i]'/)
{
print "Member ID: " $1
}
}
}
It just prints ENTER A NAME: when I execute the script file. It doesn't even get the input from the user.
From awk manual
ARGV is an array of command line arguments
That is the list of arguments passed while calling the awk sript.
you may want something like
$echo 'ENTER A NAME'
$read Name
Jesse Pinkman
$awk -v name="$Name" -F: '$2=name{print $1}' filename
123123123
123123124
Here -v option creates a variable named name in awk script and assigns the value of $Name variable from shell to name
$2=name{print $1} the $2=name selects all lines where $2 is name and prints the first column
Not sure what you're thinking about wrt using ARGV[] but here's one way to do what you want in awk:
$ awk 'BEGIN{FS=":"; msg="ENTER A NAME:"; print msg} NR==FNR{a[$2]=$0; next} $0 in a{print a[$0]} {print msg}' file -
ENTER A NAME:
Jesse Pinkman
123123124:Jesse Pinkman:1:3:4:1
ENTER A NAME:
Walter White
123123123:Walter White:1:2:3:4
ENTER A NAME:
I have below script but it sends email without any attachment. What is wrong?
sendmail /A "/home/dd/data/list.txt" "dd#gmail.com" -t << EOF
To:dd#gmail.com
Subject:List of ids
This is the message
[new line]
Everything else works as expected. Thanks.
The here document is not completed.
sendmail /A "/home/dd/data/list.txt" "dd#gmail.com" -t << -EOF
To:dd#gmail.com
Subject:List of ids
This is the message
EOF
try -EOF so the trailing EOF does not need to be in the leftmost column.
Try this, I just tested it:
/usr/sbin/sendmail -tv me#myplace.com <<%%
Subject: test of sendmail
This is the note
$(uuencode attachment.file newname.txt)
%%
I did not have time to get back to this. email address goes on line 1
Try the script below:
#!/bin/sh
# send/include list.txt file after "here document" (email headers + start of email body)
cat - "/home/dd/data/list.txt" | /usr/sbin/sendmail -i -- "dd#gmail.com" <<END
To: dd#gmail.com
Subject: List of ids
This is the message
END