Linux自动切换用户脚本,自动输入用户名密码

需要安装tcl 和expect包

实现自动切换用户:

#!/usr/bin/expect  -f

spawn su - root
expect "Password:"
send "hadoop\n"
interact


 

自动输入用户名密码ssh到其他机器:

#!/usr/bin/expect -f
spawn ssh daxin
expect "*password*"
send "root\n"
interact

expect是期望终端显示什么字符时才send字符串,需要跟随一个回车响应输入。

还可以设置超时时间,默认是10秒!

猜你喜欢

转载自blog.csdn.net/eeeeety6208/article/details/126987861