Domanda

We have a monitoring system making RRD databases. I am looking for the most light way of creating graphs from this RRD files for our HTML pages. So I don't want to store them in files. I am trying to create simple BASH CGI script, that will output image data, so I can do something like this:

<img src="/cgi-bin/graph.cgi?param1=abc"></img>

First of all, I am trying to create simple CGI script, that will send me PNG image. This doesn't work:

#!/bin/bash
echo -e "Content-type: image/png\n\n"
cat image.png

But when I rewrite this to PERL, it does work:

#!/usr/bin/perl
print "Content-type: image/png\n\n";
open(IMG, "image.png");
print while <IMG>;
close(IMG);
exit 0;

What is the difference? I would really like to do this in BASH. Thank you.

È stato utile?

Soluzione

Absence of -n switch outputs third newline, so it should be

echo -ne "Content-type: image/png\n\n"

or

echo -e "Content-type: image/png\n"

from man echo

  -n     do not output the trailing newline
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top