Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. function ssh_tunnel() {
  4. echo "Starting jump-machine-production tunnel on 127.0.0.1:2222 ....."
  5. ssh -o ExitOnForwardFailure=yes -o ServerAliveInterval=30 -NnT -L 127.0.0.1:2222:remote-production-machine:6379 jump-machine-production
  6. }
  7.  
  8. function close_ssh_tunnel() {
  9. echo "Ending tunnel session on 127.0.0.1:2222"
  10. kill `ps -ax | grep "ssh" | grep "remote-production-machine" | cut -d ' ' -f 1`
  11. }
  12.  
  13. ssh_tunnel &
  14.  
  15. #the below line registers function close_ssh_tunnel to be called during script finish.
  16. #This will be called irrespective of script success or failure.
  17. trap close_ssh_tunnel EXIT
  18.  
  19. (
  20. echo "DEL keyToBeDeleted"
  21. echo "exit"
  22. ) | telnet 127.0.0.1 2222
  23.  
  24. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement