简体   繁体   English

在Linux上自动执行SFTP / SSH提示

[英]Automate SFTP/SSH prompts on Linux

I'm particularly new to shell scripting and ssh commands and such. 我对shell脚本和ssh命令之类的东西特别陌生。 I was wondering if I could automate simple sftp prompts when uploading/downloading files from one server to another. 我想知道在将文件从一台服务器上传/下载到另一台服务器时是否可以自动执行简单的sftp提示。

Here is what I do: 这是我的工作:

  • command: sftp username@ServerHost 命令:sftp username @ ServerHost
  • Response: The authenticity of host '***' can't be established. 响应:无法确定主机“ ***”的真实性。 Are you sure you want to continue connecting (yes/no)? 您确定要继续连接(是/否)吗?
  • after I type 'yes' it asks me the password 在我输入“是”后,它会问我密码

I essentially want to automate this since I'll be calling a script which will upload a file from my source server to a remote one through an InfoSphere Datastage sequence job on the source server. 我本质上想自动化此操作,因为我将调用一个脚本,该脚本将通过源服务器上的InfoSphere Datastage序列作业将文件从源服务器上载到远程文件。

PS. PS。 Pardon my insolence if this question doesn't make sense of if it's too juvenile :) 如果这个问题没有太大意义,请原谅我的无礼:)

check out expect, that helps to automate such issues in scripts. 请查看期望值,这有助于自动化脚本中的此类问题。

Here a sample that works for me: 这是一个对我有用的示例:

#!/usr/bin/expect -f

set timeout 30

set user "coder"
set node "repohost"
set fsrc "/home/coder/Sources/sysperf/makefile"
set fdst "/tmp"
set uspw "topSecret"

spawn sftp $user@$node:$fsrc $fdst
expect_after eof {exit 1}
expect "$user@$node's password: " {send "$uspw\r"}
expect "*100%*" 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM