问题
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:
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
来源:https://stackoverflow.com/questions/28784307/use-plink-to-execute-command-oracle-sql-query-on-remote-server-over-ssh