"include: command not found" in apache logs
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
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
On 26-07-2012 06:36, cleaver at terabithia.org wrote:
[using cfg-files in shell scripts]
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
On Thu, Jul 26, 2012 at 4:52 PM, Henrik Størner <henrik at hswn.dk> 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
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.
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
participants (3)
-
cleaver@terabithia.org
-
henrik@hswn.dk
-
jlaidman@rebel-it.com.au