Hi,
I sent to you a script I wrote and do exactly what you need. Just change IP address, username and password. This script run in Linux machine, you just need to install Expect on it. Usually, Linux support Expect by default.
-If I helped you somehow, please, rate it as useful.-