Advertisement
Guest User

Scripts

a guest
Apr 18th, 2023
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.72 KB | Writing | 0 0
  1. -----------------------------------------------------------------------
  2. Script 1
  3. -----------------------------------------------------------------------
  4. #!/bin/bash
  5.  
  6. # read the parameters from the file
  7. declare -A params
  8. while read line; do
  9.   if [[ ! $line =~ ^\# && ! -z "$line" ]]; then
  10.     name=$(echo "$line" | cut -d' ' -f1)
  11.     values=$(echo "$line" | cut -d' ' -f2-)
  12.     params["$name"]="$values"
  13.   fi
  14. done < params.txt
  15.  
  16. # check if the script was called with an argument
  17. if [ -z "$1" ]; then
  18.   echo "Usage: $0 parameter"
  19.   exit 1
  20. fi
  21.  
  22. # check if the parameter matches one of the supported values
  23. if [ ! "${params[$1]+exists}" ]; then
  24.   echo "Error: unsupported parameter value. Expected values: ${!params[@]}"
  25.   exit 1
  26. fi
  27.  
  28. # set the variables based on the parameter
  29. read -r swnum pnum <<< "${params[$1]}"
  30.  
  31. ./SWreset.sh "$swnum" "$pnum"
  32.  
  33.  
  34.  
  35. -----------------------------------------------------------------------
  36. Script 2
  37. -----------------------------------------------------------------------
  38. #!/usr/bin/expect
  39.  
  40. set timeout 2
  41. set swnum [lindex $argv 0]
  42. set geport [lindex $argv 1]
  43.  
  44. spawn telnet 172.18.0.$swnum
  45.  
  46. expect "User Name: "
  47. send "username\r"
  48. expect "Password: "
  49. send "password"
  50. set timeout 1
  51.  
  52.  
  53.         expect "SW2#"
  54.         send "conf t\r"
  55. set timeout 1
  56.  
  57.         expect "SW2#<config>#"
  58.         send "int ge$gepoort\r"
  59. set timeout 1
  60.  
  61.         expect "SW2#<config>#"
  62.         send "shutdown\r"
  63. set timeout 5
  64.  
  65.         expect "SW2#<config-if>"
  66. set timeout 8
  67.  
  68.         send "no shutdown\r"
  69. set timeout 1
  70.  
  71.         send "exit\r"
  72.         expect "SW2<config>"
  73. set timeout 1
  74.  
  75.         send "exit\r"
  76.         expect "SW2#"
  77. set timeout 1
  78.  
  79.         send "exit\r"
  80. set timeout 1
  81. interact
  82.  
  83.  
  84.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement