Advertisement
Guest User

Untitled

a guest
Sep 26th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # SonicWall credentials
  4. host="XXXX"
  5. username="admin"
  6. password="XXXX"
  7.  
  8. # SonicWall CLI configuration
  9. user_pattern="User:"
  10. password_pattern="Password:"
  11. prompt="NSA 3500>"
  12. exit_command="exit"
  13. newline="\n"
  14.  
  15. # the command to run
  16. command="$1"
  17.  
  18. # use expect to establish a SonicWall CLI
  19. # session over SSH, and then execute the
  20. # command.
  21. /usr/bin/expect -c "
  22. set timeout 1
  23. spawn ssh $host
  24.  
  25. # log into SonicWall CLI interface
  26. expect \"${user_pattern}\"
  27. send \"${username}${newline}\"
  28. expect \"${password_pattern}\"
  29. send \"${password}${newline}\"
  30.  
  31. # execute the command
  32. expect \"${prompt}\"
  33. send \"${command}${newline}\"
  34.  
  35. # wait for the command to complete, and then
  36. # exit the CLI interface and terminate the
  37. # SSH session
  38. expect \"${prompt}\"
  39. send \"${exit_command}${newline}\"
  40.  
  41. # the ssh session must be interactive, or else
  42. # the SonicWall will preempt the session.
  43. interact
  44. "
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement