30 lines
820 B
Bash
Executable File
30 lines
820 B
Bash
Executable File
#!/bin/bash
|
|
# Script to stop SSH tunnels
|
|
|
|
# Check if the tunnel_pids.txt file exists
|
|
if [ ! -f "tunnel_pids.txt" ]; then
|
|
echo "No tunnel PIDs file found. No tunnels to stop."
|
|
exit 0
|
|
fi
|
|
|
|
# Read the PIDs from the file and kill each process
|
|
while read pid; do
|
|
if [ -n "$pid" ]; then
|
|
echo "Stopping tunnel with PID $pid..."
|
|
kill $pid 2>/dev/null || true
|
|
fi
|
|
done < tunnel_pids.txt
|
|
|
|
# Remove the PIDs file
|
|
rm tunnel_pids.txt
|
|
|
|
# Check for any remaining SSH tunnels
|
|
remaining_tunnels=$(ps aux | grep "ssh -N -L" | grep -v grep | wc -l)
|
|
if [ $remaining_tunnels -gt 0 ]; then
|
|
echo "Warning: There are still $remaining_tunnels SSH tunnels running."
|
|
echo "You may need to kill them manually:"
|
|
ps aux | grep "ssh -N -L" | grep -v grep
|
|
else
|
|
echo "All SSH tunnels have been stopped."
|
|
fi
|