使用Plink通过SSH在远程服务器上执行命令(Oracle SQL查询) [英] Use Plink to execute command (Oracle SQL query) on remote server over SSH

查看:980
本文介绍了使用Plink通过SSH在远程服务器上执行命令(Oracle SQL查询)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前我正在这样做:启动putty.exe,输入远程服务器IS并选择SSH登录,然后输入服务器用户名和密码.然后我必须输入sqlplus进入数据库,接下来我输入数据库用户和密码并运行select查询.在我的PC上获取输出日志.

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.

我想使用Plink或任何其他工具来自动化该过程.

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

推荐答案

您已经知道,可以使用plink(来自PuTTY软件包)来自动执行远程命令.

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

plink具有命令行开关-m,可用于在命令中指定要在远程服务器上执行的 local 文件.

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

请参见使用命令行连接工具Plink

下一步是自动化远程命令.

The next step is to automate the remote command.

我不知道sqlplus.但是从使用SQL命令行开始,我假设命令(要保存到 local 文件command.txt中)类似于:

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

其中query.txt远程文件,带有要在服务器上执行的查询.

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

最后要保存查询输出,将plink重定向到 local 文件(results.txt):

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


如果仅执行一个命令,则可以直接在plink命令行上指定它,而不必使用单独的脚本文件:


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

这篇关于使用Plink通过SSH在远程服务器上执行命令(Oracle SQL查询)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆