Skip to content

Instantly share code, notes, and snippets.

@ericwastaken
Last active October 20, 2017 04:07
Show Gist options
  • Save ericwastaken/f9fffbd780962504da64c46b2ee42764 to your computer and use it in GitHub Desktop.
Save ericwastaken/f9fffbd780962504da64c46b2ee42764 to your computer and use it in GitHub Desktop.
Stops a previously started SSH tunnel.
#!/bin/bash
# *********************************************************************
# script: ssh-forward-stop.sh
# summary: Stops an SSH Port Forward process, previously started by
# the companion script `ssh-forward-start.sh`.
#
# Tested on macOS Sierra.
#
# dependencies:
# - The forward must have been started by the companion script.
# - The PID file must be present in the current folder.
#
# *********************************************************************
pid_filename="ssh-forward.pid"
echo ""
echo "ssh-forward-stop.sh"
echo "Stops an SSH Port Forward Session, previously started."
echo "Assumes you started the Forward Session with the companion script."
echo ""
if [[ -f ${pid_filename} ]]; then
ssh_pid=$(cat ${pid_filename})
kill -9 ${ssh_pid}
rm ${pid_filename}
echo "done: ssh fw stopped!"
else
echo "error: ssh fw process not found! Start one with ssh-forward-start.sh!"
fi
echo ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment