1.安装expect
yum install expect
2.编写脚本
demo.exp:
spawn /var/www/html/imagesDirBackup.sh
expect "password:"
send "ispass\r"
3.这样,当shell脚本中出现了要求输入密码的时候,脚本就自动输入了。
本文介绍如何使用expect工具自动化执行需要密码输入的shell脚本。通过编写一个简单的demo.exp脚本,实现自动输入密码的功能。
1.安装expect
yum install expect
2.编写脚本
demo.exp:
spawn /var/www/html/imagesDirBackup.sh
expect "password:"
send "ispass\r"
3.这样,当shell脚本中出现了要求输入密码的时候,脚本就自动输入了。
752
1815
1万+

被折叠的 条评论
为什么被折叠?