Files
ai-exchange/scripts/fix_pg_hba.exp
T

28 lines
888 B
Plaintext
Executable File

#!/usr/bin/expect -f
set timeout 600
spawn ssh -o StrictHostKeyChecking=accept-new root@192.168.3.90 {python3 - <<'PY'
from pathlib import Path
hba = Path('/var/lib/pgsql/16/data/pg_hba.conf')
lines = [
'host ai_ict yuqei 172.18.0.0/16 scram-sha-256\n',
'host ai_ict yuqei 172.20.0.0/16 scram-sha-256\n',
'host ai_ict yuqei 172.21.0.0/16 scram-sha-256\n',
'host ai_ict yuqei 172.22.0.0/16 scram-sha-256\n',
'host ai_ict yuqei 172.23.0.0/16 scram-sha-256\n',
]
text = hba.read_text()
added = []
for line in lines:
if line not in text:
with hba.open('a') as f:
f.write(line)
added.append(line.strip())
print('ADDED', added)
print('TAIL')
for row in hba.read_text().splitlines()[-12:]:
print(row)
PY
su - postgres -c "psql -d postgres -c 'select pg_reload_conf();'" && echo RELOADED}
expect "*assword:*" { send "816301\r" }
expect eof