Use Plink to execute command (Oracle SQL query) on

2019-02-20 20:41发布

Currently I'm doing this: start putty.exe, input remote server IS and select SSH login, then input server username and password. Then I have to enter sqlplus to enter into database, next I put database user and password and run select query. Get output logs on my PC.

I want to automate the process using Plink or any other tool.

1条回答
女痞
2楼-- · 2019-02-20 21:18

As you already know, you can use plink (from PuTTY package) to automate remote command execution.

The plink has the command-line switch -m, that you use to specify a local file with the command to execute on the remote server.

plink user@host -pw password -m command.txt

See Using the command-line connection tool Plink


The next step is to automate the remote command.

I do not know sqlplus. But from A Using SQL Command Line, I assume the command (to be saved into the local file command.txt) is like:

sqlplus dbuser/dbpassword @query.txt

Where the query.txt is a remote file with the query to execute on the server.


Finally to save the query output, redirect the plink to a local file (results.txt):

plink user@host -pw password -m command.txt > results.txt

If you are executing one command only, you can specify it directly on the plink command-line, avoiding the separate script file:

plink user@host -pw password sqlplus dbuser/dbpassword @query.txt > results.txt
查看更多
登录 后发表回答