shell脚本之通过发送带\n字符串或expect脚本实现交互输入自动化
2017-06-19 23:25
816 查看
编写shell脚本难免遇到需要交互式输入指令的步骤:
方法一:
# cat action.sh
#!/bin/sh
read -p "enter number:" no;
read -p "enter number:" name;
echo you have entered $no,$name;
# sh action.sh
enter number:chavin
enter number:king
you have entered chavin,king
# echo -e "chavin\nking\n" | sh action.sh
you have entered chavin,king
或者
# echo -e "chavin\nking\n" > input.data
# cat input.data
chavin
king
# sh action.sh < input.data
you have entered chavin,king
案例1:使用交互式自动化为用户改密码:
# useradd chavin0101
# echo -e "dbking588\ndbking588\n" | passwd chavin0101
Changing password for user chavin0101.
New password: Retype new password: passwd: all authentication tokens updated successfully.
方法二:
使用expect实现交互式任务自动化,expect工具在一般发行版中默认没有安装,需要手工安装,这里就不演示了。
方法一:
# cat action.sh
#!/bin/sh
read -p "enter number:" no;
read -p "enter number:" name;
echo you have entered $no,$name;
# sh action.sh
enter number:chavin
enter number:king
you have entered chavin,king
# echo -e "chavin\nking\n" | sh action.sh
you have entered chavin,king
或者
# echo -e "chavin\nking\n" > input.data
# cat input.data
chavin
king
# sh action.sh < input.data
you have entered chavin,king
案例1:使用交互式自动化为用户改密码:
# useradd chavin0101
# echo -e "dbking588\ndbking588\n" | passwd chavin0101
Changing password for user chavin0101.
New password: Retype new password: passwd: all authentication tokens updated successfully.
方法二:
使用expect实现交互式任务自动化,expect工具在一般发行版中默认没有安装,需要手工安装,这里就不演示了。
相关文章推荐
- shell脚本通过expect脚本实现自动输入密码(使用expect)
- shell脚本通过expect脚本实现自动输入密码
- Linux学习-->如何通过Shell脚本实现发送邮件通知功能?
- 无密钥登录的自动脚本实现(ssh-copy-id、expect免交互输入脚本)
- 如何在shell脚本中调用expect实现自动化
- 在shell脚本中用expect 实现 scp 文件的时候不手动输入密码
- shell脚本通过expect实现自动单边无密登录功能
- shell脚本调用expect命令实现命令行自动交互
- 用expect实现shell脚本的自动交互
- shell脚本实现scp上传(expect交互),ftp上传
- shell脚本调用expect命令实现命令行自动交互
- Linux-----Shell脚本交互实现自动输入密码
- Linux学习-->如何通过Shell脚本实现发送邮件通知功能?
- 使用expect实现shell脚本中scp,ssh自动输入口令
- 通过 Shell 和 Expect 脚本实现对 IBM 刀片服务器高级管理模块固件的大量升级
- 无密钥登录的自动脚本实现(ssh-copy-id、expect免交互输入脚本)
- 通过shell脚本实现自动化安装LINUX
- 在shell脚本嵌入except代码实现免交互自动化
- Shell脚本中调用expect,实现自动输入密码的功能
- 在shell脚本中用expect 实现 scp 文件的时候不手动输入密码