The avoiding of the "HTML Generation functions" doesnt work for me.
If I start on my localhost the perlscript
#!/usr/bin/perl
print "Content-type:text/html\r\n\r\n";
print '<html>';
print '<head>';
print '<title>Hello Perl</title>';
print '</head>';
print '<body>';
print '<h2>Hello perl</h2>';
print '</body>';
print '</html>';
My browser print it out as expected:
"Hello perl"
But perldoc advices: "HTML Generation functions should no longer be used". So I tried the object oriented cgitutorial-script (perl, v5.10.0).
#!/usr/bin/perl -w
use CGI;
$q = new CGI;
print $q->header,
$q->start_html('hello world'),
$q->h1('hello world'),
$q->end_html;
The browser shows
"Internal Server Error"
If I load the above script on the terminal with
$perl mycgi.pl
it shows an expected outcome
Content-Type: text/html; charset=ISO-8859-1
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US">
<head>
<title>hello world</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<h1>hello world</h1>
</body>
</html>
What am I missing?
From your comment:
(8)Exec format error: exec of '/Library/WebServer/perling/mycgi.pl' failed
That usually indicates a problem with your shebang line. Is the shebang on the first line of your program? Does it point to an executable that really exists? Are there spurious invisible characters at the end of the line (this is sometimes the case when a program is written on Windows and run on a Unix system).
Related
Newbie question: I have a simple script that builds a text file with the sendmail headers, required blank line and then text body. When I run:
sendmail -t < email.txt
it fails with a "No recipient addresses found in header" error.
However, when I run:
cat email.txt | sendmail -t
it works and the recipients receive my email.
I'm just wondering why it is behaving this way.
I'm on an AIX 6100-09-12-1846 (oslevel -s) box.
I just tested on a Linux box and it worked both ways, so I can only assume that AIX handles it differently, but I don't know why.
Update:
The following contents are in "email.txt"
Subject: Test Email
To: foo#bar.com
From: Mail.Relay#bar.com
MIME-Version: 1.0
Content-Type: text/html
<HTML>
<HEAD>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
</HEAD>
<BODY lang=EN-US link=blue vlink=purple>
<FONT SIZE=8>
This is a test email.<BR/>
</FONT>
</BODY>
</HTML>
But only when using "|" into sendmail does it work, not when redirected using "<". I'm confused.
Any ideas?
Thanks,
racer
I have Ubuntu server(16.04) + Nagios, also I have created a script that makes a screenshot(Nagios status) every night and sends this screenshot to two recipients. But occurs problem, I receive mail with images(embed in a body, not attachment) - is OK, but my friend receives the same mail with broken images(blank files in attachment).
Any suggestion, how to solve this problem?
Script code:
#!/bin/bash
cat <<EOT | /usr/sbin/sendmail -t
TO: #email1, #email2
SUBJECT: Report: Nagios Event Log $(date +%F --date=yesterday)
MIME-Version: 1.0
Content-Type: multipart/related;boundary="XYZ"
--XYZ
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 7bit
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-15">
</head>
<body bgcolor="#ffffff" text="#000000">
Hello Team,<br>Daily Nagios report of $(date +%F --date=yesterday) is generated.
<img src="cid:part1.06090408.01060107" alt="">
<br>Best Regards, Nagios Admin
</body>
</html>
--XYZ
Content-Type: image/png;name="Nagios-EventLog-`date +%F --date="yesterday"`.png"
Content-Transfer-Encoding: base64
Content-ID: <part1.06090408.01060107>
Content-Disposition: inline; filename="Nagios-EventLog-`date +%F --date="yesterday"`.png"
$(base64 /some_path/NagiosReport/Nagios-EventLog-`date +%F --date="yesterday"`.png)
--XYZ--
EOT
You lack a newline between the MIME headers and the base64 image data.
Running base64 in a command substitution inside a here document will probably produce overlong lines in the output. Try (rough pseudocode)
( cat <<EOF
From: blah blah ...
Subject: blah blah ...
:
--XYZ
Content-description: image/png; name=etc etc
EOF
base64 file
printf "\n--XYZ--\n" ) | sendmail -oi -t
(I'm assuming you did PATH=/usr/sbin:$PATH near the top of the script so you don't have to hard-code the path to sendmail.)
If improved knowledge of MIME isn't a personal development goal, probably use a program which knows how to do this properly. Many people use mutt to send mail on their behalf without having to worry about how exactly to do it right.
As a stylistic aside, running $(date +%F) multiple times seems clunky. Just run it once and capture the output in a variable. (In the pathological case, the script runs around midnight, and you get different dates in different parts of the message!)
I am working on a remote server I want to pipe some HTML context to be displayed into an email. I have been using it as follows
| mail -s "subject" will#test.com
However when I get the email in my inbox I receive the raw HTML
?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!-- This file was created with the aha Ansi HTML Adapter. http://ziz.delphigl.com/tool_aha.php -->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="application/xml+xhtml; charset=UTF-8" />
<title>stdin</title>
</head>
<body>
How do I get an email to display the HTML commands as opposed to the raw format.
Cheers
You need to add MIME headers to your email to declare that body is not text/plain. The most portable way to to generate raw email message yourself and feed it to sendmail program ("sendmail by sendmail/postfix/exim/...)
#!/bin/sh
TO=will#test.com
# feed "here document" and STDIN to sendmail
(cat <<END; cat -) | /usr/sbin/sendmail -i $TO
Subject: SUBJECT
To: $TO
MIME-Version: 1.0
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: 8bit
END
Respected ppl ...
Im on openSUSE 12.2 and my Apache server is running fine ...
I copied the index.html which contains :
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head><title>Program 7b</title></head>
<body>
<form method="POST" action="http://localhost/cgi-bin/7b.pl">
Please Enter the Command :
<input type="text" name="command" id="command" />
<input type="submit" value="Submit" />
</form>
</body>
</html>
And the perl file as follows :
#!/usr/bin/perl
print "Content-type:text/html\n\n";
use CGI
$a = new CGI;
$comm = $a->param("command");
print "The Output of the entered command is:<br />";
system($comm);
Both files in the cgi-bin directory
But i get the error :
Premature end of script headers
On running localhost/cgi-bin/index.html in any browser ....
I have set the execution of perl files in the apache configuration ...
Kindly help with the problem ...
Regards
-SkyKOG
Apache is running index.html as a script, not simply displaying an HTML document. Apache is probably configured to run anything in the cgi directory as a script.
Move the html file into another directory.
Try the following working code :
#!/usr/bin/perl
use strict; use warnings;
use CGI;
print "Content-type:text/html\n\n";
my $a = new CGI;
my $comm = $a->param("command");
print "The Output of the entered command is:<br />";
system($comm);
An advice : never forget use strict; use warnings; and declare variables with my or our.
I am trying to use clisp to dump webpages like, e.g. to define a function "read-url", such that (read-url "http://www.kernel.org/index.html") would display the html source code like:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!-- $Id: index.shtml,v 1.422 2012/02/09 17:13:11 root Exp $ -->
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>The Linux Kernel Archives</title>
<link rel="icon" type="image/png" href="favicon.ico" />
<link rel="alternate" type="application/rss+xml"
title="Latest Linux Kernel Version RSS"
href="http://kernel.org/kdist/rss.xml" />
<link rel="stylesheet" href="/kernel.css" type="text/css" />
......
does anyone know how?
Many thanks!!
I would recommend using drakma: "a fully-featured web client".
Where you could easily write a function as:
(defun read-url (url)
(drakma:http-request url))
which will then return the corresponding (sent back by the server) html-code. It works very well and (as far as I explored it) bug-less.
try CLOCC/CLLIB/url.lisp, see with-open-url, url-get &c.