خرید بک لینک

Vote count: 1

Setup:

  • Local *nix machine with a SQL script script.sql (Postgres).
  • Remote machine remote with Postgres.
    • I can SSH in as some_user, who is a sudoer.
    • Anything with Postgres needs to be done as postgres user.
    • The server only listens on localhost:5432.

How do I execute script.sql on remote without copying it there first?

This works well:

ssh -t some_user@remote 'sudo -u postgres psql -c "COMMANDS FOO BAR"'

The -t flag means that sudo will ask for some_user's password correctly on the local terminal.

One thing remains, to be able to pipe script.sql to psql. This does not work:

ssh -t some_user@remote 'sudo -u postgres psql' < script.sql

It fails with the message:

Pseudo-terminal will not be allocated because stdin is not a terminal.
sudo: no tty present and no askpass program specified

asked 3 mins ago

- - , .

برچسب: نویسنده: استخدام کار تاريخ: سه شنبه 11 اسفند 1394 ساعت: 20:30

صفحه بندی