-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new script to run generic SQL on a remote PG server
- Loading branch information
1 parent
86de4c1
commit 906f5fa
Showing
2 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#!/usr/bin/bash | ||
|
||
### VARIABLES | ||
BASE=$( dirname "$0" ) | ||
|
||
|
||
### FUNCTIONS | ||
|
||
die() { | ||
echo "ERROR: $*" 1>&2 | ||
exit 99 | ||
} | ||
|
||
prep() { | ||
rsync "$BASE"/pgpass.cnf ${HOST}:.pgpass | ||
ssh ${HOST} chmod 600 .pgpass | ||
} | ||
|
||
|
||
test_conn() { | ||
ssh $HOST 'pg_isready -d jsmdb -h localhost -U jsmdb_user' | ||
} | ||
|
||
|
||
run_sql() { | ||
fn="$1" | ||
cat "$fn" | ssh $HOST 'psql -d jsmdb -h localhost -U jsmdb_user' | ||
} | ||
|
||
|
||
### MAIN | ||
HOST="$1" | ||
[[ -z "$HOST" ]] && die "Missing hostname" | ||
|
||
FN="$2" | ||
[[ -z "$FN" ]] && die "Missing filename" | ||
case "$FN" in | ||
(/*) SQL="$FN" ;; | ||
(*) SQL="${BASE}/${FN}" ;; | ||
esac | ||
[[ -r "$SQL" ]] || die "Cannot read file '$SQL'" | ||
|
||
prep | ||
|
||
test_conn || die "connection not ready" | ||
|
||
run_sql "$SQL" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
select 'missing display name' | ||
as Comment; | ||
SELECT | ||
lower_user_name | ||
, active | ||
, lower_first_name | ||
, lower_last_name | ||
, display_name | ||
, lower_display_name | ||
, email_address | ||
, lower_email_address | ||
FROM cwd_user | ||
WHERE ID IN (53892, 53893); | ||
|
||
select 'anyone with missing display name' | ||
as Comment; | ||
SELECT | ||
lower_user_name | ||
, active | ||
, lower_first_name | ||
, lower_last_name | ||
, display_name | ||
, lower_display_name | ||
, email_address | ||
, lower_email_address | ||
FROM cwd_user | ||
WHERE | ||
COALESCE(TRIM(display_name),'') = ''; | ||
|
||
select 'missing email address' | ||
as Comment; | ||
SELECT | ||
lower_user_name | ||
, active | ||
, lower_first_name | ||
, lower_last_name | ||
, display_name | ||
, lower_display_name | ||
, email_address | ||
, lower_email_address | ||
FROM cwd_user | ||
WHERE | ||
id IN (10671, 11070, 11095,18659, 53892, 53893, 55269, 55273, 55857, 56299, 58329, 62244); | ||
|
||
select 'anyone with missing email address' | ||
as Comment; | ||
SELECT | ||
lower_user_name | ||
, active | ||
, lower_first_name | ||
, lower_last_name | ||
, display_name | ||
, lower_display_name | ||
, email_address | ||
, lower_email_address | ||
FROM cwd_user | ||
WHERE | ||
COALESCE(TRIM(email_address),'') = ''; |