dbaccess, command line parameter
Posted in 2003
Topics: Server Administration
Hello!
I would like to do following:
in sql script file test.sql is:
select * from $1
I would like to call this sql from command line and pass parameter into it.
like: cat test.sql|dbaccess db-test - .... ???parameter
Mitja
On Fri, Dec 05, 2003 at 02:09:43PM +0100, Mitja Udovc wrote:
MU> Hello!
MU> I would like to do following:
MU> in sql script file test.sql is:
MU> select * from $1
MU> I would like to call this sql from command line and pass parameter into it.
MU> like: cat test.sql|dbaccess db-test - .... ???parameter
You can't use dbaccess in such way. Try this:
> cat my_query.sh
#!/bin/sh
if [ $0 -eq 0 ] ; then
echo "Usage: $0 table_name"
exit 1
fi
cat <<SQL | dbaccess db-test
select * from $1SQL
========================================================================
Example of usage: select all from table 'test_table':
> ./my_query.sh test_table
--
// yurik shestakov
Bourne shell:
#!/bin/sh
for what in `cat tablis`
do
echo 'select * from ${what}' | dbaccess dbname
done
Korn shell:
#!/bin/ksh
for what in $(cat tablist)
do
print "select * from ${what}" | dbaccess dbname
done
or (ksh)
#!/bin/ksh
print "select tabname from systables where tabid > 99 order by tabname"
| dbaccess dbname | sed '/tabname/d;s/ *$//;/^$/d' > list
for table in $(cat list)
do
print "select * from ${1} | dbaccess dbname
done
or (ksh):
cat > doit
#!/bin/ksh
print "select * from ${1}" | dbaccess dbname
^d
chmod 755 doit
doit tabname
and so on.
Mitja Udovc wrote:
> Hello!
>
> I would like to do following:
>
> in sql script file test.sql is:
>
> select * from $1>
> I would like to call this sql from command line and pass parameter into it.
> like: cat test.sql|dbaccess db-test - .... ???parameter
>
> Mitja
>
>
>
> #!/bin/ksh
> print "select tabname from systables where tabid > 99 order by tabname"
> | dbaccess dbname | sed '/tabname/d;s/ *$//;/^$/d' > list
> for table in $(cat list)
> do
> print "select * from ${1} | dbaccess dbname
oops -- that's
print "select * from ${table}" | dbaccess dbname
> done
>
sorry
Napisi SHELL skriptu i u njoj:
#!/bin/sh
if [ ! $# = 1 ]; then
echo "Usage: $0 ime_tablice"
exit 1
fi
dbaccess ime_baze - <<KRAJ
select * from $1KRAJ
Recimo da se skripta zove run_sql. Treba joj dati pravilna ovlastenja:
chmod 775 run_sql
i izvodis je s
run_sql neka_tvoja_tablica
Pozdrav
Nebojsa
On Fri, 5 Dec 2003 14:09:43 +0100, "Mitja Udovc" <mitja.udovc@mf.uni-lj.si>
wrote:
>Hello!
>
>I would like to do following:
>
>in sql script file test.sql is:
>
>select * from $1>
>I would like to call this sql from command line and pass parameter into it.
>like: cat test.sql|dbaccess db-test - .... ???parameter
>
>Mitja
>
------------------------------------
Remove spam block (DELETE_) to reply