是否能下列x.x.x.x利用變數的方式 讀入例如/ETC/HOSTS 分別登入不同台SERVER 執行COMMAND #!/usr/bin/expect spawn telnet x.x.x.x expect "login:" send "pom\r" expect "Password:" send "123456\r" expect "$" send "cd /home/p ...
我用的activetcl for windows 8.4.19.0 , 写了个最简单的expect脚本老是有问题: #!/bin/sh # \ exec tclsh "$0" ${1+"$@"} package require Tcl package require Tk package require expect spawn ssh2 root@server01 expect "root's password:"; send "111111\r" expect "*#"; send "ls\r" expect "*#"; send "exit\r" 可以是它始终报错 : C:\Program Files\active\bin>tclsh c:\ssh_logon.tcl send: spawn id exp4 not ...
我写了一段Perl代码, 利用expect自动登录交换机,代码如下:
use expect;
use strict;
use warnings;
sub readdata{
open(FILEHANDLE,"change.txt")||die"can not open filename:$!";
my(@array)=
aa.sh #!/usr/bin/expect # Change a login shell to tcsh set user [lindex $argv 0] spawn chsh $user expect “]:” send “/bin/tcsh ” expect eof exit 执行 ./aa.sh young spawn chsh young Changing shell for young. New shell [/bin/tcsh]: /bin/tcsh 还需要按回车,按了回车就在这里卡住了,该怎么写让它自动完成
脚本如下: #!/usr/bin/expect -f set timeout 5 spawn passwd root expect "*password:" sleep 1 send -- "something\r" expect "*password:" sleep 1 send -- "something\r" expect eof 执行结果: spawn passwd root Changing password for root. Enter login(LDAP) password: LDAP Password incorrect: try again Enter login(LDAP) password: LDAP Password incorrect: try again Enter login(LDAP) password: 然后就退出来...
我用expcet写了一个用ssh远程登陆的脚本,想批量修改linux下默认网关,最后用send "route add ***"更改了只是临时的网关,重启后还是变成原来的。想到只能修改/etc/sysconfig/network-scripts/ifcfg-eth0文件,想用sed更改,但是send "sed ***"脚本执行不起来