expect是一种自动交互语言,能实现在shell脚本中为scp和ssh等自动输入密码自动登录。下面给出scp和ssh的使用示例:1、scpexpect -c " spawn scp [email protected]:/root/1.log /root expect { \"*assword\" {set timeout 300; send \"password\r\";} \"yes/no\" {send \"yes\r\"; exp_continue;} } expect eof"2、ssh#!/bin/bash expect -c " spawn ssh [email protected] \"ls;\" expect { \"*assword\" {set timeout 300; send \"password\r\";} \"yes/no\" {send \"yes\r\"; exp_continue;} } expect eof "
(以上内容不代表本站观点。) --------------------------------- |