expect

Execute remote commands from Debian to Windows via Telnet

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-04 20:53:55
I am working on remotely executing a command line in Windows from Debian. For that, I tried to use the bash script below. Using the expect tool, it consists in connecting via telnet to the remote server, entering username and password values and sending the command line desired. #!/usr/bin/expect set timeout 20 set name 192.168.1.46 set user Administrateur set password MSapp/*2013 set cmd "TASKKILL /F /IM Tomcat6.exe" spawn telnet 192.168.1.46 expect "login:" send "$user\r" expect "password:" send "$password\r" expect "C:\Users\Administrateur>" send "$cmd\r" The telnet connection is well

76、expect同步文件|expect指定host后同步文件|构建文件分发系统|批量远程执行命令

我们两清 提交于 2019-12-04 13:52:08
1、expect同步文件 : 自动同步文件; 一台机器向一台机器同步文件: 1:在一台机器上,把文件同步到其他机器上;并添加执行权限: [root@localhost_01 sbin]# vim 4.expect [root@localhost_01 sbin]# cat 4.expect #!/usr/bin/expect set passwd "nihao123!" spawn rsync -av -e "ssh -p 56888" root@192.168.149.129:/tmp/12.txt /tmp/ expect { "yes/no" { send "yes\r"} "password:" { send $passwd\r} } expect eof [root@localhost_01 sbin]# chmod a+x 4.expect 2:执行这个脚本: ./4.expect 并查看同步后的文件内容: [root@localhost_01 sbin]# ./4.expect spawn rsync -av -e ssh -p 56888 root@192.168.149.129:/tmp/12.txt /tmp/ root@192.168.149.129's password: receiving incremental file list 12.txt sent

Ruby - Problems with Expect and Pty

岁酱吖の 提交于 2019-12-04 13:46:51
问题 I'm trying to write a Ruby script that will ssh over to a server, run a given command, and fetch the output from it. Here's what I've got so far, mostly adapted from the Programming Ruby book: require 'pty' require 'expect' $expect_verbose = true PTY.spawn("ssh root@x.y") do |reader, writer, pid| reader.expect(/root@x.y's password:.*/) writer.puts("password") reader.expect(/.*/) writer.puts("ls -l") reader.expect(/.*/) answer = reader.gets puts "Answer = #{answer}" end Unfortunately all I'm

Spawn command not found

ⅰ亾dé卋堺 提交于 2019-12-04 12:15:48
I have an error trying to run a .sh file line 2: spawn: command not found ": no such file or directory bash.sh: line 3: expect: command not found bash.sh: line 4: send: command not found #!/usr/bin/expect -f spawn sftp -o IdentityFile=MyFile.ppk 500200243@XXX.XXX.XXX.XXX expect "XXX.XXX.XXX.XXX.gatewayEnter passphrase for key 'MyFile.ppk.ppk':" send "myPassword" Any idea why it happens? It works OK for me (error from sftp: ssh: Could not resolve hostname XXX.XXX.XXX.XXX: Name or service not known ), though the .sh extension for an expect ( tcl ) script is a little off-putting ;-) Often when

Export Bash command-line-argument variables for use in embedded Expect

给你一囗甜甜゛ 提交于 2019-12-04 12:04:32
The echo test shows me my command line variables are working, but how do I pass them, export them, to be used in an embedded expect ? #!/bin/bash echo name of script is $0 echo host is $1 echo hostusername is $2 echo hostpassword is $3 expect -c 'spawn ssh -l $2 $1 < ./sf-wall_scp_bash.sh sleep 2 expect { "(yes/no)? " {send "yes\n"} exp_continue } expect { "?assword" {send "$3\r"} } sleep 1 ' If invoked with the expect shebang, it works like #!/usr/bin/expect set host [lindex $argv 0] set hostusername [lindex $argv 1] set hostpassword [lindex $argv 2] spawn ssh -l $hostusername $host sleep 2

Handle multiple statement in expect script

痞子三分冷 提交于 2019-12-04 11:44:17
I am new in expect scripting. I wrote a expect script for ssh in a linux machine,where I am facing problem in sshing on different linux machines.Below I have copied the script. !/usr/local/bin/expect set LinuxMachine [lindex $argv 0] spawn ssh root@$LinuxMachine expect "root@$LinuxMachine's password:" send "root123\n" expect "[root@Client_FC12_172_85 ~]#" send "ls" interact When I supply 10.213.172.85 from command line the expect in the 4th line , it reads as " root@10.213.172.85's password: " and the logins successfully But some linux will expect- The authenticity of host '10.213.172.108 (10

How can I assign a variable using $expect_out in TCL/EXPECT?

て烟熏妆下的殇ゞ 提交于 2019-12-04 11:09:56
问题 If I want to match DEF_23 using the following regexp: expect { -re "DEF_\[0-9]*" set result $expect_out(1,string) } why does it say no such element in array ? How does $expect_out work, and how can I capture the DEF using a regexp and assign it to the variable result ? 回答1: You're looking for expect_out(0,string) -- the array element 1,string would be populated if you had capturing parentheses in your regular expression. The expect manpage documents the use of expect_out in the documentation

How can I use Expect to enter a password for a Perl script?

北城以北 提交于 2019-12-04 08:40:52
I wish to automatically enter a password while running an install script. I have invoked the install script using the backticks in Perl. Now my issue is how do I enter that password using expect or something else? my $op = `install.sh -f my_conf -p my_ip -s my_server`; When the above is executed, a password line is printed: Enter password for the packagekey: In the above line I wish to enter the password. dsm use Expect.pm . This module is especially tailored for programatic control of applications which require user feedback #!/usr/bin/perl use strict; use warnings; use Expect; my $expect =

How to use bash script variables in expect conditional statements

隐身守侯 提交于 2019-12-04 07:34:03
I am writing a bash script and using expect to do sftp. Now in the expect block I want to access a bash variable in a conditional statement. but, I am unable to do so. Can somebody help in this. Also, the execution of this script is controlled from a c prograame and i wan't redirect the output to a log file (which again is dynamic). Can i do that and suppress all teh output on stdout here is the code !/usr/bin/bash host=$1 user=$2 pass=$3 action=$4 path=$5 echo "Starting...." function doAction { strAction="\""$action"\"" echo $strAction /usr/bin/expect <<EOF > logfile.txt **set bashaction

CAS

匆匆过客 提交于 2019-12-04 06:18:59
CAS是什么? CAS(Compare And Swap):比较并交换,它是一条并发原语。 原语属于操作系统用语范畴,是由若干条指令组成,用于完成某个功能的一个过程,并且原语的执行必须是连续的,在执行过程中不允许被中断,也就是说CAS是一条原子指令,不会造成所谓的数据不一致问题。 compareAndSet方法 public final boolean compareAndSet( int expect, int update) { return unsafe .compareAndSwapInt( this , valueOffset , expect, update); } 这是compareAndSet方法的源码,第一个参数是期望值,第二个参数是更新值,返回值是boolean类型。如果它的期望值与线程中的真实值一致,比较成功,把线程中值替换为更新值,如果比较失败,值不会改变。 代码演示: // AtomicInteger不给值默认为0AtomicInteger atomicInteger = new AtomicInteger(5);System.out.println(atomicInteger.compareAndSet(5,2019)+"\t 修改结果:"+atomicInteger.get());System.out.println(atomicInteger