"找不到命令"在错误expect脚本通过shell脚本执行 [英] "command not found" errors in expect script executed by shell script

查看:2668
本文介绍了"找不到命令"在错误expect脚本通过shell脚本执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现shell脚本调用expect脚本,因此,它不提示用户每次输入SSH密码。我开始用<一个href=\"http://stackoverflow.com/questions/4594698/using-a-variables-value-as-password-for-scp-ssh-etc-instead-of-prompting-for-u\">Using作为密码SCP,SSH等,而不是每次都提示用户输入变量的值和了解,我应该有一个 .SH 文件和 .EXP 文件。我有 expect安装(运行在我的系统期待-v 显示期望版本5.43.0 )。

I am trying to implement "shell script calling expect script" so that it does not prompt the user for entering ssh password every time. I started with Using a variable's value as password for scp, ssh etc. instead of prompting for user input every time and understood that I should have a .sh file and a .exp file. I have expect installed in my system (running expect -v shows expect version 5.43.0).

在我的 upload-to-server.sh 文件我有

cd $SOURCE_PATH/shell
./password.exp $DESTINATION_PATH $SSH_CREDENTIALS $PROJECT_INSTALLATION_PATH $PASSWORD

在我的 password.exp 文件我有

#!/usr/bin/expect -f

set DESTINATION_PATH [lindex $argv 0];
set SSH_CREDENTIALS [lindex $argv 1];
set PROJECT_INSTALLATION_PATH [lindex $argv 2];
set PASSWORD [lindex $argv 3];

spawn scp $DESTINATION_PATH/exam.tar $SSH_CREDENTIALS':/'$PROJECT_INSTALLATION_PATH
expect "password:"
send $PASSWORD"\n";
interact

在运行 upload-to-server.sh 文件我碰到下面的错误 -

On running the upload-to-server.sh file I get the following error -

./password.exp: line 9: spawn: command not found
couldn't read file "password:": no such file or directory
./password.exp: line 11: send: command not found
./password.exp: line 12: interact: command not found

我到达上述code(在EXP文件),从多个来源(不理解多少基础知识)。在一个源中的code是这样的

#!/usr/local/bin/expect
spawn  sftp  -b cmdFile user@yourserver.com
expect "password:"
send "shhh!\n";
interact

而在<一href=\"http://stackoverflow.com/questions/2242643/how-to-use-a-shell-script-to-supply-a-password-when-the-interface-asks-for-it\">another来源这样

#!/usr/local/bin/expect -f
set TESTCASE_HOME [lindex $argv 0];
set TESTCASE_LIST [lindex $argv 1];
set PASSWORD [lindex $argv 3];

set timeout 200
spawn $TESTCASE_HOME/dobrt -p $TESTCASE_HOME/$TESTCASE_LIST
expect "*?assword:*" {send -- "$PASSWORD\r";}
expect eof

有一定的差异存在 -

There are some differences there -


  • 有一个额外的 -f #!的/ usr / local / bin目录/期望

  • 期望的 assword:的{派 - $ PASSWORD \\ R;}不同于期望密码
    发嘘\\ n!;

  • there is an extra -f in the #!/usr/local/bin/expect line
  • expect "?assword:" {send -- "$PASSWORD\r";} is different from expect "password:" send "shhh!\n";

交互替换想到EOF

这是我的第一个 expect脚本所以没有太多的想法是什么,以code。任何指针?

This is my first expect script so don't have much idea what to code. Any pointers?

谢谢,结果
Sandeepan

Thanks,
Sandeepan

推荐答案

不要做任何的这个!你应该使用公共密钥认证与上面的意见建议。你要去的方式离开了明文密码,是脆弱的。

Don't do any of this! You should use public key authentication as the comment above suggests. The way you're going leaves passwords in the clear and is fragile.

公钥验证是设置比较容易的方式,例如:设置说明

Public key authentication is way easier to setup, for example: setup instructions

这篇关于&QUOT;找不到命令&QUOT;在错误expect脚本通过shell脚本执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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