Hi, I often use a shellscript that passes a query as a parameter on the commandline. The shellscript is:
Code:
#!/bin/bash
OUT="/dev/null"
while getopts ":e" OPTION; do
case $OPTION in
e) OUT="/dev/$(ps -p $PPID | awk 'NR==2{print $2}')";;
*) echo "$(basename $0): invalid option ${1}"
echo "Use \`$(basename $0)' -e for showing error output"
exit 1
esac
done
shift $((OPTIND -1))
if [ $# -ne 1 ]; then
echo "$(basename $0): invalid number of arguments"
echo "Usage: $(basename $0) [-e] \"SQLSTATEMENT\""
exit 1
fi
{
dbaccess databasename <<SQL
$*
SQL
} 2>"$OUT"
As you can see it's written for a (Suse) Linux system and possibly some shell commands in it are different from the HP-UX equivalents, but I'm not familiar with the latter.
Anyway for this you need to have dbaccess installed on the client which I believe is when Ifx client software is installed. In the script you must replace the
databasename with the actual
databasename@hostname and you can use it on the commandline like:
Code:
db -e "SELECT colname FROM tablename WHERE code = 'ABCD'"
with error output to the terminal and like:
Code:
db "SELECT colname FROM tablename WHERE code = \"ABCD\""
without error output and with escaped double quotes within the SQL string.
Maybe it's useful, I imitated it from the DB2 commandline utility with the same name. Regards,
Hans
BTW. Within the SQL string you can use regular shell variables as parameters when invoking from another script or in a for-loop on the command line like:
Code:
#!/usr/bin/ksh
db "SELECT colname FROM ${1} WHERE code = '${2}'"