The following scripts telnet into various devices called from a txt file and then run a command, log the output and then exits. However when an incorrect IP address is used the script displays the username and password entered and this is visible in the log file which is not ideal. Any idea how to insert a timeout to prevent this?
#telnet.exp
######################################################
#!/usr/bin/expect -f
# Set variables
set hostname [lindex $argv 0]
set username [lindex $argv 2]
set password [lindex $argv 1]
# Log the output
log_file -a ~/configuration-telnet.log
# Which device we are working on and at what time
send_user "\n"
send_user ">>>>> Working on $hostname @ [exec date] <<<<<\n"
send_user "\n"
spawn telnet $hostname
expect "Username:"
send "$username\n"
expect "Password:"
send "$password\n"
expect "#"
send "term len 0\r"
send "show running-config\r"
expect "end\r"
send "\r"
send "exit\r"
########################################################
#telnet.sh
########################################################
#!/bin/bash
echo -n "Username:"
read -s -e username
echo -ne '\n'
echo -n "Password:"
read -s -e password
echo -ne '\n'
# Feed the expect script a device list & the collected passwords
for device in `cat telnet-device-list.txt`; do
./telnet.exp $device $password $username;
done