mirror of
https://github.com/DictXiong/dotfiles.git
synced 2024-11-24 13:56:59 +08:00
riot: introduce sshl
This commit is contained in:
parent
d560368861
commit
45f4d9538c
31
scripts/riot
31
scripts/riot
|
@ -43,21 +43,39 @@ get_server_meta()
|
|||
# ssh
|
||||
run_ssh()
|
||||
{
|
||||
fmt_note "--> ssh to $SERVER:$PORT"
|
||||
eval ssh -p $PORT $SSH_OPTIONS $SSH_USERNAME@$SERVER
|
||||
CMD="ssh -p $PORT $SSH_OPTIONS $SSH_USERNAME@$SERVER"
|
||||
fmt_note "-->" $CMD
|
||||
eval $CMD
|
||||
}
|
||||
|
||||
# sshl
|
||||
run_sshl()
|
||||
{
|
||||
if [[ -z "$1" || "$1" != *":"* ]]; then
|
||||
fmt_fatal "invalid remote address: $1"
|
||||
fi
|
||||
while
|
||||
local port=$(shuf -n 1 -i 49152-65535)
|
||||
netstat -atun | grep -q "$port"
|
||||
do
|
||||
continue
|
||||
done
|
||||
CMD="ssh -p $PORT $SSH_OPTIONS -NC -L $port:$1 $SSH_USERNAME@$SERVER"
|
||||
fmt_note "-->" $CMD
|
||||
fmt_note " > please access localhost:$port"
|
||||
eval $CMD
|
||||
}
|
||||
|
||||
# main
|
||||
print_help()
|
||||
{
|
||||
fmt_info "usage: $0 <service> [command] [options]"
|
||||
echo "available commands: ssh (default)"
|
||||
echo "available commands: ssh (default), sshl (ssh -L)"
|
||||
}
|
||||
|
||||
router()
|
||||
{
|
||||
test -n "$1" || (print_help && fmt_fatal "invalid arguments")
|
||||
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
|
||||
if [[ -z "$1" || "$1" == "-h" || "$1" == "--help" ]]; then
|
||||
print_help
|
||||
exit
|
||||
fi
|
||||
|
@ -70,6 +88,9 @@ router()
|
|||
ssh|"" )
|
||||
run_ssh
|
||||
;;
|
||||
sshl )
|
||||
run_sshl "$3"
|
||||
;;
|
||||
* )
|
||||
print_help
|
||||
fmt_fatal "unknown command: $2"
|
||||
|
|
Loading…
Reference in New Issue
Block a user