【linux 学习】shell脚本自动化登录

版权声明:本文为博主原创文章,转载请注明出处!!!(●'◡'●) https://blog.csdn.net/Small_Mouse0/article/details/84781588

每次登录都需要输入密码,,好麻烦滴感觉,于是想做个自动登录脚本,岂不美哉^ . ^


如何输入密码是个大问题,好在有个交互输入的工具【expect】

首先需要安装一下,
【Centos】

	#查看是否安装过
	yum list | grep expect
	#安装
    sudo yum install expect

【Ubuntu】

#查看是否安装过
dpkg -l expec
#安装
sudo apt-get install expect

编写shell脚本
#!/usr/bin/expect
spawn mycli -uroot 
expect "Password:"
send "1486145487\r"
interact

【#!/usr/bin/expect】一直不知道shell脚本的第一行注释有什么用,以为仅仅是注释,实际上是制定运行程序,即用什么程序运行此脚本

交互式执行原理基本上是三步走:

  1. 运行程序
  2. 匹配交互信息
  3. 输入参数

当然这只是一个简单的Demo,好玩的还有很多O(∩_∩)O~~

猜你喜欢

转载自blog.csdn.net/Small_Mouse0/article/details/84781588