Use Plink to execute command (Oracle SQL query) on remote server over SSH

让人想犯罪 __ 提交于 2019-12-18 07:24:42

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!