Converting Linux scripts to FreeBSD?

I run an automatic counter on my FreeBSD server, my current scripts did work properly in Gentoo Linux. They do not work in FreeBSD, I get the following error.

Code:
./eq.imo.sh 
URL=http://hraun.vedur.is/ja/englishweb/eqlist.html: Command not found.
TODAYSDATE=2013-05-09: Command not found.
URL: Undefined variable.
COUNT=: Command not found.
COUNT: Undefined variable.

This I need to fix. Here is the code for the script in question.

Code:
#earthquake count shell V0.0.1
#!/bin/bash

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

I also got same script for a second counter that I am running. I can adopt this script to that counter with no issues, since they are both doing the same thing, just in different part of the world.

Thanks for the help.
 
Try that:

Code:
#!/bin/sh

#earthquake count shell V0.0.1

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
 
Works for me ;)
Code:
[tmw@foo ~]$ uname -a
FreeBSD foo 9.1-RELEASE FreeBSD 9.1-RELEASE #0 r243826: Tue Dec  4 06:55:39 UTC 2012     [email]root@obrian.cse.buffalo.edu[/email]:/usr/obj/usr/src/sys/GENERIC  i386

Code:
[tmw@foo ~]$ bash --version
GNU bash, version 4.1.11(0)-release (i386-portbld-freebsd9.1)
What is your bash and freebsd FreeBSD version? Did you try some -x to see what this script is doing?
 
I am running the following.

Code:
uname -a
FreeBSD saturn.net303.net 9.1-RELEASE FreeBSD 9.1-RELEASE #0 r243826: Tue Dec  4 06:55:39 UTC 2012     root@obrian.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC  i386

Here are the file permissions, they look good, but I might be wrong.

Code:
-rwxr-xr-x  1 root  wheel    415 May  9 05:06 eq.imo.sh

They

Code:
bash --version
GNU bash, version 4.2.42(0)-release (i386-portbld-freebsd9.1)
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

The script did work first time I did install it with mrtg, but then it just stopped working. I am seeing this error when I run the script by hand. It is the same error as before.

Code:
./eq.imo.sh 
URL=http://hraun.vedur.is/ja/englishweb/eqlist.html: Command not found.
TODAYSDATE=2013-05-09: Command not found.
URL: Undefined variable.
COUNT=: Command not found.
COUNT: Undefined variable.

I am not sure what the issue is here.
 
Look carefully at the first two lines of the script in post #1. Which line specifies the script interpreter, and which line should it be on?
 
wblock@ said:
Look carefully at the first two lines of the script in post #1. Which line specifies the script interpreter, and which line should it be on?

Thanks for this, I did use the change in the post #2 and then it worked. The command seems to be literal in FreeBSD, but that is not the case in Gentoo Linux.
 
I am still running into one issue. When the script is run in cron it returns the value 0 all the time, this does not happen when I run it manually. I am also getting inconsistent values when the data is moved to mrtg.

Here is the configuration file for mrtg. I might be missing something, but I am not sure what.

Code:
#---------Apache hits-----------------------
WorkDir: /usr/local/www/apache24/data/mrtg/
Target[localhost_eq]: `/usr/local/etc/mrtg/eq.imo.sh`
Options[localhost_eq]: gauge, integer ,perminute, nopercent, growright, noinfo
MaxBytes[localhost_eq]: 100000
YLegend[localhost_eq]: count
#Colours[localhost_eq]: GREEN#458B00
ShortLegend[localhost_eq]: quakes &nbsp;&nbsp;
LegendO[localhost_eq]: Earthquakes:
LegendI[localhost_eq]: Earthquakes:
Legend2[localhost_eq]: Earthquakes pr hour
Legend4[localhost_eq]: Max number of earthquakes
Title[localhost_eq]: Number of earthquakes Iceland
WithPeak[localhost_eq]: wmy
PageTop[localhost_eq]: <h1>Earthquakes Iceland Automatic </h1>
#------------End Apache Hits------------------
 
Make sure you have the PATH environment variable correctly specified in you crontab, something like
Code:
PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin
 
I use webmin to set up my cron jobs. In the case of this script, I set it up like this.

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

This is in the command section of webmin.

I am not sure what the issue is, but I think it belongs to its own thread. Since it is a different issue.
 
Back
Top