Technical help needed for a script issue

I need some technical help, for the reason that I am not a programmer and I never have. I guess that I never am going to be one, since I lack the talent of doing numerical math (I possibly have dyscalculia).

I problem is this, I run a internal counter on my local server. This counter helps me by telling me the total number of earthquakes during the day, week, month and a year in Iceland, it is really useful when large earthquake swarm takes place.

I used Gentoo Linux on my server, but I have now moved over to FreeBSD for technical and practical reasons. The move to FreeBSD did work as I expected, with the exception of this counter, it does not work in FreeBSD, I do not get any reading to mrtg (the counter software). The script I have been testing work when run from command line, but when I run the cron job on them. Nothing more happens and no data is handed over to mrtg.

Here are the scripts,

#!/usr/local/bin/bash

#earthquake count shell V0.0.6

URL=”http://hraun.vedur.is/ja/englishweb/eqlist.html”
TODAYSDATE=`date +%Y-%m-%d`
#TODAYSDATE=`date +%Y/%m/%d`
#TODAYSDATE=`date +%Y-%m-%d`

COUNT=`lynx -dump ${URL} | grep ${TODAYSDATE} | grep -vi updated | wc -l`
#COUNT=`wget -O ${URL} | grep ${TODAYSDATE} | grep -vi updated | wc -l`
echo ${COUNT}
echo ${COUNT}
#echo ${COUNT}
#echo “uptime”
#echo “hostname”

exit 0

This script does not give me any error, but no data is handed over to mrtg as it did in Gentoo Linux. I do not know why that it and I have been unable to resolve this issue.

The second script I was testing is this one here, more details and discussions can be found here on FreeBSD forum.

#!/usr/local/bin/bash

#earthquake count shell V0.0.7

URL=”http://hraun.vedur.is/ja/englishweb/eqlist.html”
TODAY=`date +%Y-%m-%d`
HOURS=`date +%H`
MINUTES=`date +%M`
OUT=”$TODAY.txt”

NOW=`echo “($HOURS * 60) + $MINUTES” | bc`
EARTHNUM=`wget –quiet -O – $URL | grep $TODAY | grep -vci updated`

if [ $OUT ]; then
touch $OUT
fi

echo “$NOW $EARTHNUM” >> $OUT

exit 0

When run in mrtg, I get this error here. The script runs without a issue when run it from command line.

2013-05-20 22:46:09: WARNING: Could not get any data from external command ‘/usr/local/etc/mrtg/eq.imo.sh’
Maybe the external command did not even start. (Illegal seek)

2013-05-20 22:46:09: WARNING: Problem with External get ‘/usr/local/etc/mrtg/eq.imo.sh’:
Expected a Number for ‘in’ but nothing’

2013-05-20 22:46:09: WARNING: Problem with External get ‘/usr/local/etc/mrtg/eq.imo.sh’:
Expected a Number for ‘out’ but nothing’

2013-05-20 22:46:09: ERROR: Target[localhost_eq][_IN_] ‘ $target->[0]{$mode} ‘ did not eval into defined data
2013-05-20 22:46:09: ERROR: Target[localhost_eq][_OUT_] ‘ $target->[0]{$mode} ‘ did not eval into defined data

I am bit lost what is the issue here, since the script works from command line. If anyone out there has any idea what this might be. A help is most welcomed in this matter, since I am no programmer at all and I have little understanding on how to deal with this problem.

7 Replies to “Technical help needed for a script issue”

  1. Hi,

    if the script works from command line but not from mrtg, this looks like a problem with permissions. mrtg probably runs with a specialized user-account. Has this user-account execute-permission on your script? Changing the owner or the group to the mrtg-account or group and adjusting the permissions of the script would solve the problem in this case.

    If this doesn’t help, I need more info on the permissions of the files and services and the data structure mrtg expects from the script.

    Günter

    1. Here are the permissions on the files in question. I run the command as root, since trying to run it as normal user doesn’t seem to work properly. That might just be lack of know-how on my part.

      ls -l eq.*
      -rwxr–r– 1 root wheel 670 May 14 03:30 eq.emsc.cfg
      -rwxr–r– 1 root wheel 0 May 14 03:30 eq.emsc.ok
      -rwxr–r– 1 root wheel 279 May 14 03:30 eq.emsc.sh
      -rwxr–r– 1 root wheel 455 May 14 03:30 eq.es.auto.sh
      -rwxr–r– 1 root wheel 638 May 18 19:58 eq.es.cfg
      -rwxr–r– 1 root wheel 0 May 18 19:59 eq.es.ok
      -rwxr–r– 1 root wheel 454 May 14 03:31 eq.es.py
      -rwxr-xr-x 1 root wheel 376 May 18 19:57 eq.es.sh
      -rwxr–r– 1 root wheel 442 May 14 04:40 eq.es.sh.old
      -rwxr–r– 1 root wheel 720 May 18 19:48 eq.imo.cfg
      -rwxr–r– 1 root wheel 0 May 22 18:26 eq.imo.ok
      -rwxr–r– 1 root wheel 632 May 14 03:30 eq.imo.rev.cfg
      -rwxr–r– 1 root wheel 0 May 14 03:30 eq.imo.rev.ok
      -rwxr–r– 1 root wheel 338 May 14 03:30 eq.imo.rev.sh
      -rwxr–r– 1 root wheel 632 May 14 03:30 eq.imo.rev.test.cfg
      -rwxr–r– 1 root wheel 338 May 14 03:30 eq.imo.rev.test.sh
      -rwxr-xr-x 1 root wheel 378 May 20 22:44 eq.imo.sh
      -rwxr–r– 1 root wheel 426 May 22 18:21 eq.imo.sh.old

      I did try to run this as mrtg user, but it did not work for some reason. That user might be locked by default.

      1. eq.imo.sh has execute permission for all users, so that is not the problem.

        Can you describe a bit more precise what you did when you tried to run the script as the mrtg user? Did you try su as root or as normal user?

        Günter

      2. I am using webmin to run the script. I run it like this,

        /usr/local/bin/mrtg /usr/local/etc/mrtg/eq.imo.cfg

        Webmin is running this as root (the command is run by the user root).

        When I run the old script in bash shell, I get this.

        ./eq.imo.sh.old
        9
        9

        Correct data is passed on to the shell, but this data is not passed to mrtg to read it properly when it is running in cron (I use webmin to set-up cron jobs). I do not know what the issue is, this script was working perfectly in Gentoo Linux. It does not work in FreeBSD for some reason.

        I am not sure what is going on here with this.

      3. Another idea: maybe the mrtg user has no PATH-variable set. A solution would be to set it in your script before using any commands:

        PATH=”/usr/local/bin:/usr/bin:/bin”

Comments are closed.