Last active
February 19, 2023 08:32
-
-
Save 0x5e/0eab9304979a338c618b2b83b68387c7 to your computer and use it in GitHub Desktop.
Automate telnet login
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This script is generated by chatgpt for telnet auto-login. | |
if [ $# -eq 0 ]; then | |
echo "Usage: $0 <host>" | |
exit 1 | |
fi | |
host=$1 | |
user=$(grep -A 2 "Host $host" ~/.ssh/config | grep User | awk '{print $2}') | |
password=$(grep -A 2 "Host $host" ~/.ssh/config | grep Password | sed 's/#//' | awk '{print $2}') | |
if [ -n "$user" ] && [ -n "$password" ]; then | |
expect -c " | |
spawn telnet $host | |
expect \"login:\" | |
send \"$user\r\" | |
expect \"Password:\" | |
send \"$password\r\" | |
interact | |
" | |
else | |
telnet $host | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment