expect

Tcl + Check file existence

若如初见. 提交于 2019-12-10 15:33:16
问题 I'm trying to check if a file exists or not in Tcl, but I can't seem to get a true result. Even though I know it is present. while {true} { if { [file exists $file_name] == 1} { exp_send "copy file.txt destination \r" puts " File copied!" } puts "File Not copied" } I always execute the File not copied line. I did a put for [file exists $file_name] and I always end up with 0. But I know for a fact that the file exists in the current directory. Any suggestions? EDIT: An alternative method that

Expectation on Mock Object doesn't seem to be met (Moq)

感情迁移 提交于 2019-12-10 15:20:04
问题 I'm experiencing some odd behavior in Moq - despite the fact that I setup a mock object to act a certain way, and then call the method in the exact same way in the object I'm testing, it reacts as if the method was never called. I have the following controller action that I'm trying to test: public ActionResult Search(string query, bool includeAll) { if (query != null) { var keywords = query.Split(' '); return View(repo.SearchForContacts(keywords, includeAll)); } else { return View(); } } My

expect script to ssh returns invalid command name

牧云@^-^@ 提交于 2019-12-10 13:34:06
问题 I am trying to write an expect script which would ssh into a server, send sudo su, then check the iptables status and put the output in a log file on the server. Below is the script. 1 #!/usr/bin/expect 2 exp_internal 1 3 log_user 0 4 set timeout 10 5 set password "******" 6 7 spawn /usr/bin/ssh -l subhasish *.*.*.* -p 10022 8 9 expect { 10 -re "password: " {send "$password\r"} 11 -re "$ " {send "sudo su\r"} 12 -re "[sudo] password for subhasish:" {send "$password\r"} 13 -re "# " {send

bash: does expect work with multiple password prompts?

a 夏天 提交于 2019-12-10 10:05:37
问题 I am currently using expect to pass in passwords so my scripts can run automatically without me having to sit around and type in the same password over and over again. Important: Please don't comment about how big of a security risk this is or how I should be using ssh keys, I would use those if I could, but the setup I have to work with doesn't allow it. My code looks like the following: #!/bin/sh PASS=mypassword /usr/bin/expect -c " spawn python Tools/python/install.py expect -nocase \

linux系统之间文件传输

旧城冷巷雨未停 提交于 2019-12-10 08:56:55
linux之间文件传输(转) linux的scp命令 linux 的 scp 命令 可以 在 linux 之间复制 文件 和 目录; scp 命令 scp 可以在 2个 linux 主机间复制文件; 命令基本格式: scp [可选参数] file_source file_target 从 本地 复制到 远程 复制文件: * 命令格式: scp local_file remote_username@remote_ip:remote_folder 或者 scp local_file remote_username@remote_ip:remote_file 或者 scp local_file remote_ip:remote_folder 或者 scp local_file remote_ip:remote_file 第1,2个指定了用户名,命令执行后需要再输入密码,第1个仅指定了远程的目录,文件名字不变,第2个指定了文件名; 第3,4个没有指定用户名,命令执行后需要输入用户名和密码,第3个仅指定了远程的目录,文件名字不变,第4个指定了文件名; * 例子: scp /home/space/music/1.mp3 root@www.cumt.edu.cn:/home/root/others/music scp /home/space/music/1.mp3 root@www.cumt

expect实现命令行简单交互

余生颓废 提交于 2019-12-10 08:42:53
在服务器开发中,有时候需要自动同步另一个服务器的一个文件,这时候就需要通过scp来把文件复制到当前服务器目录下,如: scp -r -P 2214:lex@192.168.120.204:/data/user/user.profile ./ scp需要认证用户名和密码,可以通过在对方服务器通过密钥对来验证不需要输入密码验证,但除了这个还有其他方法,能够实现在执行scp命令时,要求输入密码时能够自动输入密码吗? linux提供了一个Expect的工具,Expect是Unix系统中用来进行自动化控制和测试的软件工具,由DonLibes制作,作为Tcl脚本语言的一个扩展,应用在交互式软件中如telnet,ftp,Passwd,fsck,rlogin,tip,ssh等等。该工具利用Unix伪终端包装其子进程,允许任意程序通过终端接入进行自动化控制;也可利用Tk工具,将交互程序包装在X11的图形用户界面中。 简单地说,expect是一个工具,可以根据用户设定的规则和系统进程进行自动化交互,例如远程登陆的密码输入、自动化的执行远程命令。 expect的安装很简单,几个命令就搞定,具体谷歌(不是百度,程序员不要用百度)。 这是一个ssh自动登录的脚本: #!/usr/bin/expect spawn ssh root@192.168.22.194 expect "*password:" send

Expect Command And How To Automate Shell Scripts Like Magic

烈酒焚心 提交于 2019-12-09 22:13:21
In the previous post, we talked about writing practical shell scripts and we saw how it is easy to write a shell script. Today we are going to talk about a tool that does magic to our shell scripts, that tool is the Expect command or Expect scripting language. Expect command or expect scripting language is a language that talks with your interactive programs or scripts that require user interaction. Expect scripting language works by expecting input, then the Expect script will send the response without any user interaction. You can say that this tool is your robot which will automate your

iterm2 自动连接服务器配置

做~自己de王妃 提交于 2019-12-09 16:47:52
expect脚本配置 expect这个语言,我觉得提供了和进程交互的能力吧,具体语句含义见参考。 下面有2种情况,第一种是直接连服务器,也就是需要输入密码的方式,当然在服务器把你电脑公钥放上去,密码也不用输了。第二种情况的话,大部分公司去连线上服务器,都要经过跳板机,我们公司使用的是JumpServer,跳板机如何配置也不讲了。 普通服务器脚本 connect.sh #!/usr/bin/expect set timeout 30 spawn ssh [ lindex $argv 0 ] @ [ lindex $argv 1 ] expect "password" send "[lindex $argv 2]\r\n" expect " $* " send "cd [lindex $argv 3]/\n" send "tail -200f [lindex $argv 4]\n" interact 直接使用方式如下 ./connect.sh { username } { host } { password } { directory } { logFile } 跳板机脚本 jump.sh #!/usr/bin/expect spawn ssh jhost expect "*" { send "[lindex $argv 0]\n" } expect " $* " { send "cd

How to give password in shell script?

坚强是说给别人听的谎言 提交于 2019-12-09 12:56:35
问题 In a shell script file I am using some commands like scp and make install which ask for my password. I run a shell script to compile a big project, and after some time it asks for my password for using scp . I need to wait for that process and give the password after that. I just want to do it all by shell script without interaction, so how can I avoid being prompted for the password here? 回答1: If you can't use ssh trust and must enter the password later on in your script, use read -s -p

Why doesn't my git auto-update Expect script work?

杀马特。学长 韩版系。学妹 提交于 2019-12-08 20:43:15
问题 I wanted to make a script that would update all of my GitHub repositories. I would just need to enter my Username and my Password, and the script would go through a list of repositories, call git push and provide the necessary information via a supplementary Expect script. This is my bash script: #! /bin/bash echo "Updating GitHub projects from project_list.txt." echo read -p "GitHub username: " un read -p "GitHub password: " -s pw echo echo while read line do eval dir=$line echo "Updating:"