linux 脚本交互

yum install expect

首行不是 #!/bin/bash ,注意

send 密码时 后面要么加个\r,要么加个\n

#!/usr/bin/expect
spawn scp root@192.168.137.18:/dev/acq200/data/03 /data1/abc/
set timeout 3
expect "password:"
send "123456\n"
interact

更详细的:

http://www.thegeekstuff.com/2010/10/expect-examples/

http://www.thegeekstuff.com/2010/12/5-expect-script-command-line-argument-examples/

http://wenku.baidu.com/view/64eff008581b6bd97f19ea03.html

后面加不加 -f的问题 下面这个可以测试:

-c的意思是用命令行执行

expect also allows you to execute it directly in the command line using -c 

echo '#! /usr/bin/expect -f
puts aaa' >flagf.exp
chmod +x flagf.exp
./flagf.exp -c 'puts 456'

输出 

456
aaa

echo '#! /usr/bin/expect
puts aaa' >flagf.exp
./flagf.exp -c 'puts 456'

输出

aaa

You can make the expect not interpret the command line arguments using — flag.

加了-f 会把你后面的当做参数而不是 expect的选项。

$ cat  print_cmdline_args.exp
#!/usr/bin/expect
puts 'argv0 : [lindex $argv 0]';
puts 'argv1 : [lindex $argv 1]';
While executing the above script, pass the command line options, which will be treated like an argument (instead of expect options) as shown below.
$ expect print_cmdline_args.exp -d -c
argv0 : -d
argv1 : -c

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值