- This will explain how to run a command via an SSH tunnel by
- Opening the tunnel
- Running the command
- Closing the tunnel
- Assuming the script is call sshtunncomm this script can be used by running following:
- Please note that port forwarding to be handled via ssh config or other external
sshtunncomm
#!/bin/bash
function usage {
echo "Usage $basename $0
Please note that port forwarding to be handled via ssh config or other external
This requires backgcomm"
}
if [ -z "$2" ];then
usage
else
titl=sshop`date +%Y%m%d%H%M%S`
tunsvr=$1
comm="${@: 2}"
backgcomm new ${titl} ssh ${tunsvr}
sleep 2s # wait for ssh tunnel to establish
${comm}
backgcomm stop ${titl}
fi
|