I am writing a shell script to run bunch of queries in postgres.
This is the script that I have written.
#!/bin/sh
host="172.16.7.102"
username="priyank"
dbname="truaxis"
x=1
echo "Connection done"
while [ $x -le 3 ]
do
x=$(($x + 1 ))
echo "Connection $x"
psql -h $host $dbname $username << EOF
select * from students where sid = $x;
EOF
done
There are two issues with this script.
-
pgtest1.sh: 17: Syntax error: end of file unexpected (expecting “done”)
-
how do I pass $x in the sql dynamically
I want to create new db connection per iteration.
I am new to both postgre and shell.
Thanks
Priyank
You need to have EOF in its own line alone (without space etc)
then in your script