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
fiecho “$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.
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
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.
I did try to run this as mrtg user, but it did not work for some reason. That user might be locked by default.
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
I am using webmin to run the script. I run it like this,
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.
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.
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”
That did solve this issue for me. Now the script is working as it suppose to do.
Thanks for the help.
Even better:
PATH=$PATH:”/usr/local/bin:/usr/bin:/bin”
This would preserve the old $PATH if it is already set.
/Tomas