dbt2-shell script problem

Started by Jonas Jabout 16 years ago3 messages
#1Jonas J
autoramajj@gmail.com

Hi guys,

I get the dbt2 project from the git tree. And i'm trying to make it work
with postgres. The problem is in one of the dbt2 shell scripts. Since I dont
understand of Shell Script Programing, here is my problem: (I will post the
script on the end)

1 - I executed:
dbt2-pgsql-load-db -d /tmp/fodao
2 - I got the error:

dbt2-pgsql-load-db -d /tmp/fodao
[: 77: x: unexpected operator
[: 77: no: unexpected operator
Loading customer table...
COPY customer FROM '/tmp/fodao/.data' WITH NULL AS '';
ERROR: could not open file "/tmp/fodao/.data" for reading: No such file or
directory

3 - I think the correct place should be '/tmp/fodao/customer.data' instead
of "/tmp/fodao/.data"

Can anyone help me with this Bash Script ??

Mant thanks in advace,
Jonas

--- here comes the scrip:
#!/bin/sh

#
# This file is released under the terms of the Artistic License.
# Please see # the file LICENSE, included in this package, for details.
#
# Copyright (C) 2002-2008 Mark Wong & Open Source Development Labs, Inc.
#

if [ -z ${DBNAME} ]; then
echo "DBNAME not defined."
exit 1
fi

BACKGROUND="no"

usage()
{
echo "usage: `basename $0` -d <dir> [-b] [-l <port>] [-t]"
echo " <dir> is where the data files are."
}

while getopts "bd:l:t" OPT; do
case ${OPT} in
b)
BACKGROUND="yes"
;;
d)
DBDATA=${OPTARG}
;;
l)
PORT=${OPTARG}
;;
t)
TABLESPACES_FLAG="-t"
;;
esac
done

if [ "x${DBDATA}" = "x" ]; then
usage
exit 1
fi

if [ ! "x${PORT}" = "x" ]; then
PORTARG="-p ${PORT}"
fi

# Load tables
# This background stuff is honestly kinda ugly. IMO the right way to do this
# is to utilize make -j

load_table2() {
$1 "$2" || exit 1
$1 "$3" || exit 1
}

load_table() {
table=$1
if [ "x$2" == "x" ]; then
file=$table.data
else
file=$2.data
fi

local sql="COPY $table FROM '${DBDATA}/$file' WITH NULL AS '';"
local cmd="psql ${PORTARG} -e -d ${DBNAME} -c "
if [ "${BACKGROUND}" == "yes" ]; then
echo "Loading $table table in the background..."
load_table2 "${cmd}" "${sql}" "VACUUM ANALYZE $table;" &
else
echo "Loading $table table..."
${cmd} "${sql}" || exit 1
fi
}

load_table customer
load_table district
load_table history
load_table item
load_table new_order
load_table order_line
load_table orders order
load_table stock
load_table warehouse

wait

# load C or pl/pgsql implementation of the stored procedures
#if true; then
# ${DIR}/dbt2-pgsql-load-stored-procs -l ${PORT} -t c|| exit 1
#else
# ${DIR}/dbt2-pgsql-load-stored-procs -l ${PORT} -t plpgsql || exit 1
#fi

exit 0

#2Robert Haas
robertmhaas@gmail.com
In reply to: Jonas J (#1)
Re: dbt2-shell script problem

On Mon, Jan 11, 2010 at 4:18 PM, Jonas J <autoramajj@gmail.com> wrote:

I get the dbt2 project from the git tree. And i'm trying to make it work
with postgres. The problem is in one of the dbt2 shell scripts. Since I dont
understand of Shell Script Programing, here is my problem: (I will post the
script on the end)

Well this isn't really a "help" list... especially not for
shell-script programming... especially for shell-scripts that aren't
even part of PostgreSQL.

But having said that... I think you must be running a wonky version of sh.

$ DBNAME=rhaas ./broken-script -d /tmp/fodao
Loading customer table...
COPY customer FROM '/tmp/fodao/customer.data' WITH NULL AS '';
ERROR: relation "customer" does not exist

...Robert

#3Jonas J
autoramajj@gmail.com
In reply to: Robert Haas (#2)
Re: dbt2-shell script problem

Thanks for your support,

The problem was that Ubuntu links /bin/sh to /bin/dash and not /bin/bash,
that makes some scripts crashing. I done the correct linking and everything
works fine now.
Also thanks for Mark Wong support,

Jonas,

2010/1/11 Robert Haas <robertmhaas@gmail.com>

Show quoted text

On Mon, Jan 11, 2010 at 4:18 PM, Jonas J <autoramajj@gmail.com> wrote:

I get the dbt2 project from the git tree. And i'm trying to make it work
with postgres. The problem is in one of the dbt2 shell scripts. Since I

dont

understand of Shell Script Programing, here is my problem: (I will post

the

script on the end)

Well this isn't really a "help" list... especially not for
shell-script programming... especially for shell-scripts that aren't
even part of PostgreSQL.

But having said that... I think you must be running a wonky version of sh.

$ DBNAME=rhaas ./broken-script -d /tmp/fodao
Loading customer table...
COPY customer FROM '/tmp/fodao/customer.data' WITH NULL AS '';
ERROR: relation "customer" does not exist

...Robert

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers