PuTTY脚本来登录主机 [英] PuTTY scripting to log onto host
问题描述
我使用PuTTY远程登录我学校的主机。登录后,我们需要执行以下步骤:
- 输入用户名
- 输入密码
- 命令add oracle
- 命令sqlplus
- 输入用户名
- 输入密码
我将在本学期课程中登录这个主机,一个脚本,将消除上述步骤的冗余。忽略在脚本中显示我的密码的明显安全漏洞,我将如何实现这一点?我对脚本没有经验,所以您的反馈非常感谢。感谢!
编辑:我使用Putty的命令行选项,我可以绕过步骤1-2使用:
putty -loadhost-l用户名-pw密码
我还创建了一个如下所示的shell文件:
#!/ bin / bash
add oracle10g
sqlplus用户名密码
使用-m选项将此选项添加到命令行,它看起来像PuTTY登录到主机,然后立即退出。有没有办法保持我的会话在运行shell文件后打开或者我使用-m选项错误?以下是我一直关注的PuTTY指南的链接: http://the.earth .li /〜sgtatham / putty / 0.60 / htmldoc / Chapter3.html 。
这里是我试图从命令行运行的总命令 - 行:
putty -loadhost-l username -pw password -mc:\test.sh
在朋友的帮助下想出了这一点。 -m
PuTTY选项将在执行shell文件后立即结束会话。我已经做了,我已经创建了一个批处理脚本 putty.bat
与我的Windows机器上的这些内容:
@echo off
putty -loadhost-l username -pw password
这将远程登录到Linux主机。在主机端,我创建了一个名为 sql
的shell文件,内容如下:
#!/ bin / tcsh
add oracle10g
sqlplus用户名密码
我的主机的Linux版本使用 tcsh
。其他Linux版本可能会使用 bash
,所以只需用bash替换tcsh即可。
自动执行这些步骤现在可以通过两个简单的步骤完成:
- 双击
putty.bat
。这会打开PuTTY并将我登录到主机。 - 运行命令
tcsh sql
。这会将oracle工具添加到我的主机,并将我登录到sql数据库。
I'm using PuTTY to remotely log onto my school's host. Upon logging in, we are required to do these steps:
- enter username
- enter password
- command "add oracle"
- command "sqlplus"
- enter username
- enter password
I will be logging into this host a lot over the course of this semester and I was hoping to create a script that would eliminate the redundancy of the above steps. Ignoring the obvious security oversights of having my password in the script, how would I achieve this? I have zero experience with scripting, so your feedback is greatly appreciated. Thanks!
Edit: I played around with the command-line options for Putty and I was able to bypass steps 1-2 using:
putty -load "host" -l username -pw password
I've also created a shell file that looks like so:
#!/bin/bash
add oracle10g
sqlplus username password
When I try to add this option to the command-line using the -m option, it looks like PuTTY logs into the host and then immediately exits. Is there a way to keep my session open after running the shell file or am I using the -m option wrongly? Here is a link to a PuTTY guide that I have been following: http://the.earth.li/~sgtatham/putty/0.60/htmldoc/Chapter3.html.
Here is the total command that I am trying to run from the command-line:
putty -load "host" -l username -pw password -m c:\test.sh
Figured this out with the help of a friend. The -m
PuTTY option will end your session immediately after it executes the shell file. What I've done instead is I've created a batch script called putty.bat
with these contents on my Windows machine:
@echo off
putty -load "host" -l username -pw password
This logs me in remotely to the Linux host. On the host side, I created a shell file called sql
with these contents:
#!/bin/tcsh
add oracle10g
sqlplus username password
My host's Linux build used tcsh
. Other Linux builds might use bash
, so simply replace tcsh with bash and you should be fine.
To summarize, automating these steps are now done in two easy steps:
- Double-click
putty.bat
. This opens PuTTY and logs me into the host. - Run command
tcsh sql
. This adds the oracle tool to my host, and logs me into the sql database.
这篇关于PuTTY脚本来登录主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!