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

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

问题描述

目前我这样做:启动putty.exe,输入远程服务器IS并选择SSH登录,然后输入服务器用户名和密码.然后我必须输入 sqlplus 进入数据库,接下来我输入数据库用户和密码并运行选择查询.在我的 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重定向到本地文件(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天全站免登陆