Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- read -p "User: " user
- read -s -p "Password: " pass
- echo
- echo
- tmpfile="tmp_cisco.txt"
- prompt=".#|\(config\)#|\(config-if\)#"
- cat $1 |
- while IFS=' ' read -r line || [[ -n "$line" ]]; do
- if [[ $(echo "$line" | grep -Po "(\d{1,3}\.){3}\d{1,3}") ]]; then
- host=$(echo "$line" | grep -Po "(\d{1,3}\.){3}\d{1,3}")
- tmpfile=$(echo "$host" | sed "s/\.//g").txt
- echo "set timeout 15" >> $tmpfile
- echo "spawn telnet $host" >> $tmpfile
- echo "expect -re \"ame:\"" >> $tmpfile
- echo "send $user" >> $tmpfile
- echo "send \"\r\"" >> $tmpfile
- echo "expect -re \"assword:\"" >> $tmpfile
- echo "send $pass" >> $tmpfile
- echo "send \"\r\"" >> $tmpfile
- echo "expect -re \"$prompt\"" >> $tmpfile
- echo "send \""config terminal"\"" >> $tmpfile
- echo "send \"\r\"" >> $tmpfile
- echo "send \"\r\"" >> $tmpfile
- echo "expect -re \"$prompt\"" >> $tmpfile
- elif [[ $(echo "$line" | grep "int gi") ]]; then
- echo "send \""$line"\"" >> $tmpfile
- echo "send \"\r\"" >> $tmpfile
- echo "send \"\r\"" >> $tmpfile
- echo "expect -re \"$prompt\"" >> $tmpfile
- elif [[ $(echo "$line" | grep "traffic-shape") ]]; then
- echo "send \""$line"\"" >> $tmpfile
- echo "send \"\r\"" >> $tmpfile
- echo "send \"\r\"" >> $tmpfile
- echo "expect -re \"$prompt\"" >> $tmpfile
- elif [[ $(echo "$line" | grep "rate-limit") ]]; then
- echo "send \""$line"\"" >> $tmpfile
- echo "send \"\r\"" >> $tmpfile
- echo "send \"\r\"" >> $tmpfile
- echo "expect -re \"$prompt\"" >> $tmpfile
- echo "send \""exit"\"" >> $tmpfile
- echo "send \"\r\"" >> $tmpfile
- echo "send \"\r\"" >> $tmpfile
- echo "expect -re \"$prompt\"" >> $tmpfile
- echo "send \""exit"\"" >> $tmpfile
- echo "send \"\r\"" >> $tmpfile
- echo "send \"\r\"" >> $tmpfile
- echo "expect -re \"$prompt\"" >> $tmpfile
- echo "send \""write"\"" >> $tmpfile
- echo "send \"\r\"" >> $tmpfile
- echo "send \"\r\"" >> $tmpfile
- echo "expect -re \"$prompt\"" >> $tmpfile
- echo "send \""Y"\"" >> $tmpfile
- echo "send \"\r\"" >> $tmpfile
- echo "send \"\r\"" >> $tmpfile
- echo "expect -re \"$prompt\"" >> $tmpfile
- echo "send \"exit\\r"\" >> $tmpfile
- expect -f $tmpfile
- rm $tmpfile
- fi
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement