Xymon Mailing List Archive search

"include: command not found" in apache logs

5 messages in this thread

list Jeremy Laidman · Thu, 26 Jul 2012 14:20:59 +1000 ·
There are a couple of shell scripts under cgi-bin that do this:

 . /path/to/xymonserver.cfg

Unfortunately, I have an "include" in that file.  So whenever I either do a
report (report.sh) or look at a snapshot view (snapshot.sh) I get this kind
of thing in the Apache log:

[Wed Jul 25 09:45:18 2012] [error] [client 192.168.1.11]
/usr/lib/xymon/server/etc/xymonserver.cfg: line 4: include: command not
found, referer: https://servername/xymon-cgi/report.sh

My include specifies a file called xymonserver-local.cfg, in which I define
server-specific configurations such as XYMONSERVERHOSTNAME and
XYMONSERVERIP.  So these won't be seen by these two CGI scripts.  I doubt
that any of the definitions in my include file are important.  However, if
I had ALL of my definintions in an include file, and xymonserver.cfg
consisted only of "include otherfile.cfg", I wonder what would break.

It's obvious that the way the definitions are added into the CGI script's
environment is not appropriate for the type of file - "Even though it might
look like a shell-script, it is NOT."  Furthermore, this extra line appears
to be redundant, given that $CGI_SNAPSHOT_OPTS and $CGI_REP_OPTS both
include "--env $XYMONENV", and $XYMONENV is set to
/path/to/xymonserver.cfg.  So I suspect that this line can be taken out
altogether.

Cheers
Jeremy
list Japheth Cleaver · Wed, 25 Jul 2012 21:36:59 -0700 (PDT) ·
quoted from Jeremy Laidman
There are a couple of shell scripts under cgi-bin that do this:

 . /path/to/xymonserver.cfg

Unfortunately, I have an "include" in that file.  So whenever I either do
a
report (report.sh) or look at a snapshot view (snapshot.sh) I get this
kind
of thing in the Apache log:

[Wed Jul 25 09:45:18 2012] [error] [client 192.168.1.11]
/usr/lib/xymon/server/etc/xymonserver.cfg: line 4: include: command not
found, referer: https://servername/xymon-cgi/report.sh

My include specifies a file called xymonserver-local.cfg, in which I
define
server-specific configurations such as XYMONSERVERHOSTNAME and
XYMONSERVERIP.  So these won't be seen by these two CGI scripts.  I doubt
that any of the definitions in my include file are important.  However, if
I had ALL of my definintions in an include file, and xymonserver.cfg
consisted only of "include otherfile.cfg", I wonder what would break.

It's obvious that the way the definitions are added into the CGI script's
environment is not appropriate for the type of file - "Even though it
might
look like a shell-script, it is NOT."  Furthermore, this extra line
appears
to be redundant, given that $CGI_SNAPSHOT_OPTS and $CGI_REP_OPTS both
include "--env $XYMONENV", and $XYMONENV is set to
/path/to/xymonserver.cfg.  So I suspect that this line can be taken out
altogether.

Cheers
Jeremy

I've proposed a patch to help with this kind of situation which adds
"source " and ". " as synonyms for "include " to give you a little more
flexibility in this regard.

(Obviously, this would only work with single sourced files and not the
full-on "directory " directive.)

Does this seem like it would do what you need?


Regards,

-jc
Attachments (1)
list Henrik Størner · Thu, 26 Jul 2012 07:48:12 +0200 ·
quoted from Jeremy Laidman
On 26-07-2012 06:20, Jeremy Laidman wrote:
There are a couple of shell scripts under cgi-bin that do this:

  . /path/to/xymonserver.cfg
Hmm - they shouldn't do that, I cannot remember why it is there.
quoted from Japheth Cleaver
It's obvious that the way the definitions are added into the CGI
script's environment is not appropriate for the type of file - "Even
though it might look like a shell-script, it is NOT."  Furthermore, this
extra line appears to be redundant, given that $CGI_SNAPSHOT_OPTS and
$CGI_REP_OPTS both include "--env $XYMONENV", and $XYMONENV is set to
/path/to/xymonserver.cfg.  So I suspect that this line can be taken out
altogether.
I believe you're right. I'll do that in the files generated when 
installing Xymon.


Regards,
Henrik
list Henrik Størner · Thu, 26 Jul 2012 08:52:27 +0200 ·
On 26-07-2012 06:36, user-87556346d4af@xymon.invalid wrote:

[using cfg-files in shell scripts]
quoted from Japheth Cleaver
I've proposed a patch to help with this kind of situation which adds
"source " and ". " as synonyms for "include " to give you a little more
flexibility in this regard.

(Obviously, this would only work with single sourced files and not the
full-on "directory " directive.)
I'm not too happy about doing that, especially since it doesn't handle the 'directory' include.

The correct way of doing this is to either run your script with xymoncmd - so all of the environment is setup before your script even starts - or to use xymoncfg to generate a single file with all of the include- and directory-stuff done. So instead of

#!/bin/sh
source /etc/xymon/xymonserver.cfg

you should do

#!/bin/sh
FN=`mktemp`
xymoncfg /etc/xymon/xymonserver.cfg >$FN
source $FN
rm $FN

The need for a temporary file is a bit of a kludge, so perhaps the attached patch for xymoncfg is a better solution. This provides a "-s" and "-c" option which will cause xymoncfg to output environment-variable definitions in Korn- or C-shell format, so you can do

#!/bin/sh
eval `xymoncfg -s /etc/xymon/xymonserver.cfg`

Similar to what you do with "ssh-agent". Does this seem like a workable solution ?


Regards,
Henrik
Attachments (1)
list Jeremy Laidman · Fri, 27 Jul 2012 15:54:04 +1000 ·
On Thu, Jul 26, 2012 at 4:52 PM, Henrik Størner <user-ce4a2c883f75@xymon.invalid> wrote:

The need for a temporary file is a bit of a kludge, so perhaps the attached
patch for xymoncfg is a better solution. This provides a "-s" and "-c"
option which will cause xymoncfg to output environment-variable definitions
Similar to what you do with "ssh-agent". Does this seem like a workable
solution ?
Awesome.

J