typora/note/Shell/expect 自动应答 tcl语言.md
2024-12-12 10:48:55 +08:00

407 B

  • 与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