Hi all,
I'm writing a bash script to login into my servers using a set of few regularly used passwords and collect stats.
Requirements
1. N possible passwords
2. Multiple ssh attempts.
However written, I'm unable to either try out all passwords or 3 time ssh login attempts. I'm unable to exactly figure out how to achieve this -
Code:
#!/bin/bash
passwords=(abc123 Password123 new123 linux_2 thomas45)
echo "IP of the server to connect :"
read IP
i="0"
if [$i -lt ${#passwords[@]}] # Try all known Passwords
while [$VAR="true"]
do
for j in {1..3} # Try 3 SSH attempts else re-spawn
do
VAR=$(expect -c "
spawn ssh root@$IP -o StrictHostKeyChecking=no
expect{
"password:" {send "${passwords[$i]}\r"}
"#" {interact}
}")
done
done
fi
# Collect server stats here
exit