typora/note/Shell/expect 自动应答 tcl语言.md

27 lines
407 B
Markdown
Raw Normal View History

2024-12-11 21:48:55 -05:00
- 与shell结合
```
#! /bin/bash
while read ip pass
do
/usr/bin/expect <<-END &>/dev/null
spawn ssh root@$ip
expect {
"yes/no" { send "yes\r";exp_continue }
"passwprd:" { send "$pass\r" }
}
expect "#" { send "useradd yy1;rm -rf /tmp/*;exit\r" }
expect eof
END
echo "$ip 用户创建完毕"
done < ip.txt
```
- 并发执行
```
tr ":" " " < /ip.txt | while read ip pass
do
{
command
}&
done
```