How to create multiple users using expect.?

Hi, guys. I need help on some expect problem.

#!/usr/bin/expect
set user [lindex $argv 0]
set password [lindex $argv 1]
set newuser [lindex $argv 2]
spawn telnet x.x.x.x
expect login*
send �root\r�
expect Password*
send �123546\r�
send "useradd $newuser\r"
send "exit\r"
interact

I can add 1 user using expect script, but how do I add 300 with names like Tom1,Tom2,Tom3.....,Thank you all very much.

See if you have the command newusers on the target o/s. It's in some versions of linux like redhat. It allows creation of users using a file. I would try ssh without expect if that is available to you.

1 Like