Bash cgi will not return an image

We have a monitoring system that creates RRD databases. I am looking for the easiest way to create charts from these RRD files for our HTML pages. Therefore, I do not want to store them in files. I am trying to create a 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 a simple CGI script that will send me a PNG image. This does not work:

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

But when I rewrite this in PERL, it works:

#!/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 really would like to do it in BASH. Thank.

+4
source share
1 answer

-n ,

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

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

man echo

  -n     do not output the trailing newline
+4

Source: https://habr.com/ru/post/1536591/


All Articles