Advertisement
Guest User

Untitled

a guest
Mar 28th, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. read -p "User: " user
  4. read -s -p "Password: " pass
  5. echo
  6. echo
  7.  
  8. tmpfile="tmp_cisco.txt"
  9. prompt=".#|\(config\)#|\(config-if\)#"
  10.  
  11. cat $1 |
  12. while IFS=' ' read -r line || [[ -n "$line" ]]; do
  13.  
  14.  
  15. if [[ $(echo "$line" | grep -Po "(\d{1,3}\.){3}\d{1,3}") ]]; then
  16.  
  17. host=$(echo "$line" | grep -Po "(\d{1,3}\.){3}\d{1,3}")
  18. tmpfile=$(echo "$host" | sed "s/\.//g").txt
  19.  
  20. echo "set timeout 15" >> $tmpfile
  21. echo "spawn telnet $host" >> $tmpfile
  22. echo "expect -re \"ame:\"" >> $tmpfile
  23. echo "send $user" >> $tmpfile
  24. echo "send \"\r\"" >> $tmpfile
  25. echo "expect -re \"assword:\"" >> $tmpfile
  26. echo "send $pass" >> $tmpfile
  27. echo "send \"\r\"" >> $tmpfile
  28. echo "expect -re \"$prompt\"" >> $tmpfile
  29. echo "send \""config terminal"\"" >> $tmpfile
  30. echo "send \"\r\"" >> $tmpfile
  31. echo "send \"\r\"" >> $tmpfile
  32. echo "expect -re \"$prompt\"" >> $tmpfile
  33.  
  34. elif [[ $(echo "$line" | grep "int gi") ]]; then
  35.  
  36. echo "send \""$line"\"" >> $tmpfile
  37. echo "send \"\r\"" >> $tmpfile
  38. echo "send \"\r\"" >> $tmpfile
  39. echo "expect -re \"$prompt\"" >> $tmpfile
  40.  
  41. elif [[ $(echo "$line" | grep "traffic-shape") ]]; then
  42.  
  43. echo "send \""$line"\"" >> $tmpfile
  44. echo "send \"\r\"" >> $tmpfile
  45. echo "send \"\r\"" >> $tmpfile
  46. echo "expect -re \"$prompt\"" >> $tmpfile
  47.  
  48. elif [[ $(echo "$line" | grep "rate-limit") ]]; then
  49.  
  50. echo "send \""$line"\"" >> $tmpfile
  51. echo "send \"\r\"" >> $tmpfile
  52. echo "send \"\r\"" >> $tmpfile
  53. echo "expect -re \"$prompt\"" >> $tmpfile
  54. echo "send \""exit"\"" >> $tmpfile
  55. echo "send \"\r\"" >> $tmpfile
  56. echo "send \"\r\"" >> $tmpfile
  57. echo "expect -re \"$prompt\"" >> $tmpfile
  58. echo "send \""exit"\"" >> $tmpfile
  59. echo "send \"\r\"" >> $tmpfile
  60. echo "send \"\r\"" >> $tmpfile
  61. echo "expect -re \"$prompt\"" >> $tmpfile
  62. echo "send \""write"\"" >> $tmpfile
  63. echo "send \"\r\"" >> $tmpfile
  64. echo "send \"\r\"" >> $tmpfile
  65. echo "expect -re \"$prompt\"" >> $tmpfile
  66. echo "send \""Y"\"" >> $tmpfile
  67. echo "send \"\r\"" >> $tmpfile
  68. echo "send \"\r\"" >> $tmpfile
  69. echo "expect -re \"$prompt\"" >> $tmpfile
  70. echo "send \"exit\\r"\" >> $tmpfile
  71.  
  72. expect -f $tmpfile
  73. rm $tmpfile
  74. fi
  75.  
  76. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement