cisco.sh

Dieses Script ermöglicht einen automatischen Login auf Cisco-Switche inkl. automatischem „enable“ (sofern die Kennwörter gleich sind):

#!/bin/sh
 
# Passwort
PASS="passwort"
PROGDIR=`dirname $0`
 
rm -f $PROGDIR/login.expect
touch $PROGDIR/login.expect
chmod u+x $PROGDIR/login.expect
 
cat << EOF > $PROGDIR/login.expect
#!/usr/bin/expect
spawn telnet $1
expect {
  "Password:" {
    send "$PASS\r"
    exp_continue
  }
  "Name:" {
    send "enable\r"
    exp_continue
  }
  "#" {
    interact
  }
  "% Bad passwords" {
    send_user "invalid password or account\n"
    exit
  }
  timeout {
    send_user "connection timed out\n"
    exit
  }
  eof {
    send_user "connection to $host failed: $expect_out(buffer)"
    exit
  }
}
EOF
 
$PROGDIR/login.expect
rm -f $PROGDIR/login.expect

Aufruf mit „cisco.sh cat1.mydomain.de“ oder via IP.


Revision #1
Created 27 July 2021 10:09:55 by magenbrot
Updated 27 July 2021 10:10:22 by magenbrot