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'
输出
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