-
Notifications
You must be signed in to change notification settings - Fork 0
/
search_db_xpath.sh
executable file
·56 lines (45 loc) · 1.07 KB
/
search_db_xpath.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/bash
if [ "$1" == "setup" ]; then
if [ $# -ne 3 ]; then
echo $0: usage: search_db_xpath setup [username] [servername]
fi
username=$2
servername=$3
connectionstring=$username@$servername.cnx.org
echo "Copying SQL file to server..."
scp search_db_xpath.sql $connectionstring:~/. || exit 1
echo "...done."
echo "Creating functions on server..."
ssh $connectionstring <<EOSSH || exit 1
psql -U rhaptos -h /var/run/postgresql -d repository <<EOSQL
\i search_db_xpath.sql
\q
EOSQL
exit
EOSSH
echo "...done."
exit
fi
if [ $# -ne 5 ]; then
echo $0: usage: search_db_xpath [username] [servername] [xpath] [filename] [output-filename]
exit 1
fi
username=$1
servername=$2
xpath=$3
filename=$4
outputfile=$5
connectionstring=$username@$servername.cnx.org
echo "SSH to server..."
ssh $connectionstring <<EOSSH || exit 1
psql -U rhaptos -h /var/run/postgresql -d repository <<EOSQL
\o $outputfile;
SELECT * FROM search_db_xpath(e'$xpath', '$filename');
\q
EOSQL
echo "...done."
exit
EOSSH
echo "Copying file to this machine..."
scp $connectionstring:~/$outputfile .
echo "...done"