1.yum install expect 需要使用这个命令 2.编写 shell脚本 vi test.sh #!/bin/sh echo 'su user[root]!' expect -c " spawn su - root expect ":" send "your password " interact " echo "ok!" ~ 3.执行脚本./test.sh
![](https://img2020.cnblogs.com/blog/623921/202102/623921-20210205132715002-962160794.png)
亲测~~有效...~~~
1.yum install expect 需要使用这个命令 2.编写 shell脚本 vi test.sh #!/bin/sh echo 'su user[root]!' expect -c " spawn su - root expect ":" send "your password " interact " echo "ok!" ~ 3.执行脚本./test.sh
亲测~~有效...~~~