expect 打开文件
2015-11-26 15:23
561 查看
#!/bin/bash content='Line' expect <<EOF set file "hello.txt" set fd [open \$file r] set n 0 while {[gets \$fd line] != -1} { incr n puts "$content\$n: \$line" } close \$fd EOF
#!/usr/bin/expect -f set fd [open /etc/passwd r] set data [read $fd] puts $data ### 这样就可以输出每一行 close $fd
把本地文件中的命令,执行在远程机上
,执行结束后,自动退出远程端
#!/usr/bin/expect -f set ip 192.168.6.**** set user ******* set password ******* set timeout 1 spawn ssh $user@$ip expect { "*yes/no" { send "yes\r"; exp_continue} "*password:" { send "$password\r" } } expect "pc0003" send "ls -lh\r" set fd [open ./com r] while {[gets $fd line] != -1} { expect "pc0003" send "$line \r" } close $fd expect eof #interact
相关文章推荐
- javascript iframe中打开文件,并检测iframe存在否
- Linux中使用expect脚本实现远程机器自动登录
- shell中嵌套执行expect命令实例
- expect实现批量修改linux密码脚本分享
- expect实现单台、多台服务器批量scp传输文件
- Powershell使用OpenFileDialog打开文件示例
- shell结合expect写的批量scp脚本工具
- expect用法
- expect
- Linux 远程执行命令,expect
- 打开文件很慢
- expect应用
- shell:expect实现非root用户切换脚本
- expect ssh ftp
- Expect 自动任务 集中部署
- expect 交互式脚本写法
- expect实现自动化模拟输入scp/ssh
- linux expect 用法
- CRemoteExec远程执行类
- MFC 打开路径带有中文名的文件