Guest User

Untitled

a guest
Mar 22nd, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. # Ask the user which object type they would like to rename
  2. echo "Which network object type would you like to edit? "
  3. echo "policy"
  4. echo "netgroup"
  5. echo "zonegroup"
  6. echo "host"
  7. echo "iprange"
  8. echo "ipaddr"
  9. echo "subnet"
  10. echo "netmap"
  11. #echo "all"
  12. # I would like to add an "all" variable that would equate to the 8 object
  13. # types listed above (policy through netmap)
  14. # Read in the user input and assign the variable name "object".
  15. read object
  16. # The following command will search for the objects in its respective table.
  17. cf -TJK name $object q | tail -n +3 |sed 's/ *$//' |grep " " >temp
  18. # Use the Internal Field Separator in order to assign the x variable to the
  19. entire object name.
  20. IFS="`printf 'nt'`"
  21. for x in `cat temp`
  22. do
  23. # The following command output is assigned to the y variable which will
  24. become the new name.
  25. y=`printf "$x" | tr ' ' '_'`
  26. cf $object modify name="$x" newname=$y
  27. done
  28.  
  29. # Create arrays
  30. my_array=()
  31. all_objects=(policy netgroup zonegroup host iprange ipaddr subnet netmap)
  32. # Ask the user which object type they would like to rename
  33. echo "Which network object type would you like to edit? "
  34. for o in "${all_objects[@]}"; do
  35. echo "$o"
  36. done
  37. echo "all"
  38. # Read in the user input and assign the variable name "object".
  39. read object
  40. if [ "$object" = all ]; then
  41. for o in "{all_objects[@]}"; do
  42. # The following command will search for all objects in their respective tables.
  43. my_array+=($(cf -TJK name "$o" q | tail -n +3 |sed 's/ *$//' |grep " "))
  44. done
  45. else
  46. # The following command will search for the objects in its respective table.
  47. my_array+=($(cf -TJK name "$object" q | tail -n +3 |sed 's/ *$//' |grep " "))
  48. fi
  49. # Use the Internal Field Separator in order to assign the x variable to the entire object name.
  50. IFS="$(printf 'nt')"
  51. for x in "${my_array[@]}"; do
  52. # The following command output is assigned to the y variable which will become the new name.
  53. y=$(printf "$x" | tr ' ' '_')
  54. cf "$object" modify name="$x" newname="$y"
  55. done
Add Comment
Please, Sign In to add comment