linux expect常见用法
expect有什么用呢?
自动进行shell交互,自动填充相应信息
比如scp 拷贝文件时,需要输入密码,并且每执行一次都需要重新输入.
我觉得特别麻烦,所以写了一个自动scp的脚本,再也不需要输入密码了
#!/usr/bin/expect -f set loginpass "123456" set cmd_prompt "]#|~]?" set timeout 300 set project_module "$argv" spawn scp -r -P22 /Users/whuanghkl/work/mygit/lanproxy/proxy-${project_module}/target/proxy-${project_module}-0.0.1.jar [email protected]:/home/whuang/software/proxy-server-0.0.1/lib expect { -re "assword:" { send "$loginpass\r" } -re "Permission denied, please try again." { exit } -re "Connection refused" { exit } timeout { exit } eof { exit } } interact
expect如何接收命令行参数
$argv