Display Pie Chart/Bar Graph in microsoft outlook email using UNIX commands/Shell scripts


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Display Pie Chart/Bar Graph in microsoft outlook email using UNIX commands/Shell scripts
# 1  
Old 03-16-2015
Display Pie Chart/Bar Graph in microsoft outlook email using UNIX commands/Shell scripts

I have a shell script which executes to write html codes into a text file. My next step is to email the text file so that receiving person (people who i send email to) should be able to see pie/chart or bar graph (whatever i design in my code) in their email. Following is the example of a sample shell script which writes a html file with pie chart codes in it. I need to email this html file and the receiver needs to see the pie chart in their email.

Code:
#! /bin/bash

TEMP=$(mktemp -t chart.XXXXX)
QUERY1=33
QUERY2=67
cat > $TEMP <<EOF
<html>
<head>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">

google.load('visualization', '1.0', {'packages':['corechart']});

google.setOnLoadCallback(drawChart);

function drawChart()
{

        var data = new google.visualization.DataTable();
        data.addColumn('string', 'Title');
        data.addColumn('number', 'Value');
        data.addRows([
                        ['Error Percentage', $QUERY1],
                        ['No Error Percentage', $QUERY2]
                    ]);

        var options = {'title':'Errors',
                        'width':400,
                        'height':300};

        var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
        chart.draw(data, options);
}
</script>
</head>

<body>
<div id="chart_div"></div>
</body>
</html>
EOF


I have tried using mutt and send email but nothing works.

I have tried :
Code:
mutt -e 'set content_type="text/html"' someone@gmail.com -s "test_piechart" < chart.XXXXX

chart.XXXXX is the filename created when the shell script is executed and this chart.XXXXX file will have the html content in it.

Appreciate your time and help.

Thanks!!
Moderator's Comments:
Mod Comment Please use CODE tags for ALL sample input, output, and code segments.

Last edited by Don Cragun; 03-16-2015 at 02:31 AM.. Reason: Add CODE and ICODE tags.
# 2  
Old 03-16-2015
Quote:
Originally Posted by bikerboy
I have a shell script which executes to write html codes into a text file. My next step is to email the text file so that receiving person (people who i send email to) should be able to see pie/chart or bar graph (whatever i design in my code) in their email. Following is the example of a sample shell script which writes a html file with pie chart codes in it. I need to email this html file and the receiver needs to see the pie chart in their email.

Code:
#! /bin/bash

TEMP=$(mktemp -t chart.XXXXX)
QUERY1=33
QUERY2=67
cat > $TEMP <<EOF
<html>
<head>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">

google.load('visualization', '1.0', {'packages':['corechart']});

google.setOnLoadCallback(drawChart);

function drawChart()
{

        var data = new google.visualization.DataTable();
        data.addColumn('string', 'Title');
        data.addColumn('number', 'Value');
        data.addRows([
                        ['Error Percentage', $QUERY1],
                        ['No Error Percentage', $QUERY2]
                    ]);

        var options = {'title':'Errors',
                        'width':400,
                        'height':300};

        var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
        chart.draw(data, options);
}
</script>
</head>

<body>
<div id="chart_div"></div>
</body>
</html>
EOF


I have tried using mutt and send email but nothing works.

I have tried :
Code:
mutt -e 'set content_type="text/html"' someone@gmail.com -s "test_piechart" < chart.XXXXX

chart.XXXXX is the filename created when the shell script is executed and this chart.XXXXX file will have the html content in it.

Appreciate your time and help.

Thanks!!
Moderator's Comments:
Mod Comment Please use CODE tags for ALL sample input, output, and code segments.
No. The command TEMP=$(mktemp -t chart.XXXXX) (and your shell script above) does not create a file named chart.XXXXX, it creates a file with a name more like:
/var/folders/hb/zmv2wvjx07sc_lqgzmwrsvt80000gn/T/chart.XXXXX.32sQA0j4 (your pathname will vary, but this is the pathname of the file created when I ran that command on my system a few minutes ago).

So, the command:
Code:
mutt -e 'set content_type="text/html"' someone@gmail.com -s "test_piechart" < chart.XXXXX

will probably generate an error message saying something like:
Code:
bash: chart.XXXXX: No such file or directory

unless you created a file by that name some other way.

If you use mktemp to create your output file, your script needs to also produce output that will allow other programs that want to use that data to find the output file it created.

What operating system are you using? On most systems, the options to mutt should be presented before the operands. Did you get any output at all from the commands you ran?
# 3  
Old 03-16-2015
Thanks Don for the reply.

Let me put it this way (and sorry if i did confuse you at the beginning)

Say the shell script executed and i have a file "chart.abcde". Now, I need to email this file "chart.abcde" and the receiving person should see pie chart/ bar graph in their email.

Code for the "chart.abcde" ( which is nothing but an html file)

Code:
<html>
<head>

<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">


google.load('visualization', '1.0', {'packages':['corechart']});


google.setOnLoadCallback(drawChart);

function drawChart() {


var data = new google.visualization.DataTable();
data.addColumn('string', 'Title');
data.addColumn('number', 'Value');
data.addRows([
['a', 99],
['b', 25],
['c', 50],
['d', 33],
['e', 22]
]);

var options = {'title':'Errors',
'width':1000,
'height':1000};


var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
</head>

<body>

<div id="chart_div"></div>
</body>
</html>


When i try to send this file through mutt, i do receive an email with the subject name on it but no pie chart is displayed.

Thanks,

---------- Post updated at 10:38 AM ---------- Previous update was at 10:37 AM ----------

By the way , the operating system is Linux.
# 4  
Old 03-16-2015
You are making a bad assumption. While HTML email is evil.. worse than that would be to allow javascript in such emails. By default javascript is disallowed for inline html inside of Outlook.
# 5  
Old 03-16-2015
Thanks for the reply!.

Any workaround or do I have to drop this whole idea?
# 6  
Old 03-16-2015
Consider the "deprecated" api from google:

Code:
<html>
<body>
<h1> My Pie Chart </h1>
<img src="https://chart.googleapis.com/chart?chs=600x300&amp;chd=t:43.2,10.9,21.8,14.4,9.6&amp;cht=p3&amp;chdl=a|b|c|d|e&amp;chl=43.2%|10.9%|21.8%|14.4%|9.6%" />
</body>
</html>

# 7  
Old 03-16-2015
Great! It did work. Many thanks for the help!

---------- Post updated at 12:44 PM ---------- Previous update was at 12:43 PM ----------

I used the same code you put above and ran:

mutt -e 'set content_type="text/html"' someone@gmail.com -s "test_piechart" < test.html

---------- Post updated at 01:08 PM ---------- Previous update was at 12:44 PM ----------

Last question, how about i wish to represent my date in a bar graph format? Whats the code for it?
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

UNIX commands and scripts

Hi guys, Hoping someone can help with the below - involves basic commands and some scripting. Thanks so much in advance for your amazing time and help. 3. The file /etc/profile contains the default initialization options for your shell. Produce a unique list of all variables with uppercase... (1 Reply)
Discussion started by: edujs7
1 Replies

2. Shell Programming and Scripting

UNIX script email to outlook report format

I have a ksh script that emails a report to outlook from a Unix Solaris. On server the report formatted perfectly. However, the email version the format is not. On the server report looks like this: TN Region Old SPiAD Server Order/Req Local Status NAAC Status Request Date New... (1 Reply)
Discussion started by: mrn6430
1 Replies

3. Shell Programming and Scripting

Generate draft email in Outlook with shell script.

Hi All, Is there any way to create a draft mail with HTML body in Outlook using Shell script. (2 Replies)
Discussion started by: Girish19
2 Replies

4. Programming

Draw Bar Graph for GNUPLOT

For example, I have a file called data.txt. And the content is: Iker_Casillas 181 Raphael_Varane 182 Sergio_Ramos 182May I know how to write a script for gnuplot, so I can have a bar graph as the column 1 will be the x and column 2 will be the y? And I hope that the x value can be seen clearly.... (0 Replies)
Discussion started by: Tzeronone
0 Replies

5. Shell Programming and Scripting

Send SAS Graph in Email Body from UNIX

Hi Friends, I am trying to send a graph in Body of HTML Email which is generated using a SAS Code. But, I am not able to see the picture, Instead seeing a red cross mark in Email Body. Could you please help me in fixing this problem? Also, I do not have a Shared Place (or) a web server to... (0 Replies)
Discussion started by: Samuels
0 Replies

6. Shell Programming and Scripting

Automatic generate 3D pie Graph

Hello all, I need the scripts automatic generate 3D pie Graph. What I have now is as below: Run at terminal by $ CMD R BATCH graph.R # 3D Exploded Pie Chart library(plotrix) slices <- c(20, 15, 4, 15, 8) lbls <- c("Media", "Document", "DB", "Others", "Available") pct <-... (5 Replies)
Discussion started by: sheikh76
5 Replies

7. UNIX for Dummies Questions & Answers

Is it possible to install microsoft outlook on unix

Hi Every one, I have to install microsoft outlook on unix operating system. We can install microsoft outlook on Linux operating system using WINE HQ Emulator. Like wise any Emulator , interface or compatibility layer for running Windows Applications. Please give some suggestions links to do... (3 Replies)
Discussion started by: carthikn
3 Replies

8. UNIX for Dummies Questions & Answers

?Using Unix commands in Microsoft (Windows') DOS Prompt?

I ran a search for "Unix Dos" in the search field box and checked a few pages' results but did not find what I was looking for. I am trying to find out if there are choices of applications that would enable using Unix commands inside a Windows environment, particularly the DOS Prompt. The only... (2 Replies)
Discussion started by: HLee1981
2 Replies

9. UNIX for Advanced & Expert Users

Unable to send eMail from a UNIX-Host ( using mailx ) to a Outlook-email-addres(Win)

Hi A) I am able to send eMail using mailx from a UNIX ( solaris 8 ) host to my Outlook-email-ID : FName.Surname@Citigroup.com ( This is NOT my actual -eMail-ID). But in Outlook the "From :" eMail address is displayed as " usr1@unix-host1.unregistered.email.citicorp.com " .i.e the words... (2 Replies)
Discussion started by: Vetrivela
2 Replies

10. UNIX for Dummies Questions & Answers

Unix to MicroSoft Outlook Mails

I want to send a text file from Unix as an attachment to a Microsoft Outlook address. I have tried the 'elm' command which does this. But it is in an interactive mode. I want this to be automatically done by a program. Is there any other way to this? (3 Replies)
Discussion started by: Deepali Potnis
3 Replies
Login or Register to Ask a Question