比如scp文件从另外的主机上来的时候,需要输入密码,怎么写道shell里面自动输入密码
excpect
是用于提供自动交互的工具。比如你要用ssh或者 telnet登录服务器的时候,命令行下提示需要输入用户和密码等
项目主页: http://expect.sourceforge.net
这里有详细介绍和用法:http://www.pythonclub.org/linux/expect
#!/usr/bin/expect
set timeout 10
spawn ssh god@god.bread.so
expect {
"*yes/no*" {
send "yes\n";
exp_continue;
}
"*password:*" {
send "your password\r";
exp_continue;
}
"*bash*" {
send "ssh god@remote.bread.so\r";
exp_continue;
}
"Password:" {
send "remote server password\r";
}
}
interact
请参考前几天我写的一个 通过跳板机自动登录服务器脚本
用expect是可以的,之前我写过一篇博客,简单介绍了下,希望对你有所帮助
http://quxiao.github.io/blog/2012/05/13/add-startup-programe-with-expect/