mirror of
https://github.com/DictXiong/dotfiles.git
synced 2024-11-24 13:27:01 +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
|
# ssh
|
||||||
run_ssh()
|
run_ssh()
|
||||||
{
|
{
|
||||||
fmt_note "--> ssh to $SERVER:$PORT"
|
CMD="ssh -p $PORT $SSH_OPTIONS $SSH_USERNAME@$SERVER"
|
||||||
eval 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
|
# main
|
||||||
print_help()
|
print_help()
|
||||||
{
|
{
|
||||||
fmt_info "usage: $0 <service> [command] [options]"
|
fmt_info "usage: $0 <service> [command] [options]"
|
||||||
echo "available commands: ssh (default)"
|
echo "available commands: ssh (default), sshl (ssh -L)"
|
||||||
}
|
}
|
||||||
|
|
||||||
router()
|
router()
|
||||||
{
|
{
|
||||||
test -n "$1" || (print_help && fmt_fatal "invalid arguments")
|
if [[ -z "$1" || "$1" == "-h" || "$1" == "--help" ]]; then
|
||||||
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
|
|
||||||
print_help
|
print_help
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
@ -70,6 +88,9 @@ router()
|
||||||
ssh|"" )
|
ssh|"" )
|
||||||
run_ssh
|
run_ssh
|
||||||
;;
|
;;
|
||||||
|
sshl )
|
||||||
|
run_sshl "$3"
|
||||||
|
;;
|
||||||
* )
|
* )
|
||||||
print_help
|
print_help
|
||||||
fmt_fatal "unknown command: $2"
|
fmt_fatal "unknown command: $2"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user