Convenient ssh tunnel+proxy to use library access to journal pages
Using a ssh tunnel and local socks proxy in a browser is a convenient way to access journal pages that check for the IP range of the university. This script opens a ssh tunnel and launches a chromium session with the according proxy sessions.
#!/bin/bash
if [ "$#" -ne 1 ]; then
echo "Need ssh address as parameter, e.g. $0 myserver.com"
exit 1
fi
#cluster to access
cluster=$1
echo "Trying to opening tunnel to $cluster."
# Start at some port
port="8042"
scanning=true
nco=`netstat -an`
while $scanning
do
echo " - Checking port $port ..."
if [[ "$nco" != *":$port"* ]]; then
echo " port free."
echo "Use Ctrl+C to exit connection and stop chromium."
echo
chromium --proxy-server="socks5://localhost:$port" &
scanning=false
cpid=$!
trap "echo 'Stop chromium ...'; kill $cpid;" EXIT
ssh -N -D localhost:$port $cluster
fi
if [ $port -lt 9000 ]; then
port=$[$port+1]
else
echo "No free port found. Aborting"
scanning=false
fi
done