Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Computer Resources
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Monitor
Service Desk
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IMGW
Computer Resources
Commits
afc1732f
Commit
afc1732f
authored
4 years ago
by
Michael Blaschek
Browse files
Options
Downloads
Patches
Plain Diff
bug fix port forward
parent
1ea1e061
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
SSH-VPN-VNC/connect2jet.sh
+61
-26
61 additions, 26 deletions
SSH-VPN-VNC/connect2jet.sh
with
61 additions
and
26 deletions
SSH-VPN-VNC/connect2jet.sh
100644 → 100755
+
61
−
26
View file @
afc1732f
#!/bin/bash
#!/bin/bash
# By Michael Blaschek
# By Michael Blaschek
# Date 18.01.2021
# Date 18.01.2021
# CC BY 4.0 International
# CC BY 4.0 International
# University of Vienna, Austria
# University of Vienna, Austria
# Description:
# Description:
# Connect to Jet via a gateway server
# Connect to Jet via a gateway server
help
(){
help
()
{
cat
<<
EOF
cat
<<
EOF
$0
-g [gateway] -p [port] user@remote
$0
-g [gateway] -p [port]
-r [remote-port]
user@remote
Options:
Options:
-g [gateway] gateway server, e.g. user@login.univie.ac.at
-g [gateway] gateway server, e.g. user@login.univie.ac.at
-p [port] port to forward from jet to local, egv VNC port
-p [port] port to forward from jet to local, egv VNC port
-r [port] remote port if not the same as port
Example:
Example:
$0
-g [U:Account-Username]@login.univie.ac.at [Jet-Username]@jet01.img.univie.ac.at
$0
-g [U:Account-Username]@login.univie.ac.at [Jet-Username]@jet01.img.univie.ac.at
...
@@ -20,15 +21,18 @@ Example:
...
@@ -20,15 +21,18 @@ Example:
EOF
EOF
}
}
while
getopts
"g:p:h"
flag
;
while
getopts
"g:p:r:h"
flag
;
do
do
case
"
${
flag
}
"
in
case
"
${
flag
}
"
in
g
)
gateway
=
${
OPTARG
}
;;
g
)
gateway
=
${
OPTARG
}
;
;;
p
)
port
=
${
OPTARG
}
;;
p
)
port
=
${
OPTARG
}
;
;;
r
)
rport
=
${
OPTARG
}
;;
h|
*
)
help
;
exit
0
;;
h
|
*
)
esac
help
exit
0
;;
esac
done
done
shift
$((
OPTIND
-
1
))
shift
$((
OPTIND
-
1
))
command
=
""
command
=
""
remote
=
$1
remote
=
$1
script
=
$(
basename
$0
)
script
=
$(
basename
$0
)
...
@@ -40,25 +44,56 @@ if [ "${remote}" == "" ]; then
...
@@ -40,25 +44,56 @@ if [ "${remote}" == "" ]; then
fi
fi
if
[
-n
"
${
port
}
"
]
;
then
if
[
-n
"
${
port
}
"
]
;
then
echo
"Forwarding Port:
$port
"
# -L local_port:destination_server_ip:remote_port
command
=
"-L
${
port
}
:localhost:
${
port
}
"
if
[
-n
"
${
rport
}
"
]
;
then
echo
"Forwarding Port:
$rport
to
$port
"
command
=
"-L
${
port
}
:localhost:
${
rport
}
"
else
echo
"Forwarding Port:
$port
to
$port
"
command
=
"-L
${
port
}
:localhost:
${
port
}
"
rport
=
$port
# make sure we use this
fi
fi
# Check if names are in .ssh/config
remote_status
=
false
gateway_status
=
false
if
[
-e
$HOME
/.ssh/config
]
;
then
# check if hosts are there
cat
$HOME
/.ssh/config |
grep
-i
'Host ${remote}'
>
/dev/null
if
[
$?
-eq
0
]
;
then
remote_status
=
true
fi
if
[
-n
${
gateway
}
]
;
then
cat
$HOME
/.ssh/config |
grep
-i
'Host ${gateway}'
>
/dev/null
if
[
$?
-eq
0
]
;
then
gateway_status
=
true
fi
fi
fi
fi
if
[
-n
"
${
gateway
}
"
]
;
then
if
[
-n
"
${
gateway
}
"
]
;
then
echo
"
$gateway
"
|
grep
'@'
>
/dev/null
echo
"
$gateway
"
|
grep
'@'
>
/dev/null
if
[
$?
-eq
1
]
;
then
if
[
$?
-eq
1
]
&&
[
!
$gateway_status
]
;
then
echo
"Please give: [user]@[server], not
$gateway
"
echo
"Could fail if not: [user]@[server], trying:
$gateway
"
exit
1
fi
if
[
-n
"
${
port
}
"
]
;
then
echo
"Using gateway:
$gateway
to
$remote
"
echo
"Port Forwarding via the gateway: "
ssh
-L
${
port
}
:localhost:
${
port
}
-t
$gateway
ssh
-L
${
port
}
:
${
gateway
}
:
${
rport
}
${
remote
}
echo
"
$(
date
)
| ssh -L
$port
:localhost:12345 -t
$gateway
'ssh -L 12345:
${
gateway
}
:
${
rport
}
${
remote
}
'"
>>
.
${
script
/.sh/.log
}
else
else
echo
"Using gateway:
$gateway
to
$remote
"
echo
"Using gateway:
$gateway
to
$remote
"
ssh
$command
-t
$gateway
'
ssh ${command} ${remote}
'
ssh
$command
-t
$gateway
ssh
${
command
}
${
remote
}
echo
"
$(
date
)
| ssh
$command
-t
$gateway
'ssh
${
command
}
${
remote
}
'"
>>
.
${
script
/.sh/.log
}
echo
"
$(
date
)
| ssh
$command
-t
$gateway
'ssh
${
command
}
${
remote
}
'"
>>
.
${
script
/.sh/.log
}
fi
fi
else
else
if
[
!
$remote_status
]
;
then
echo
"Could fail if not: [user]@[server]"
fi
echo
"Direct connection to:
${
remote
}
"
echo
"Direct connection to:
${
remote
}
"
ssh
${
command
}
${
remote
}
ssh
${
command
}
${
remote
}
echo
"
$(
date
)
| ssh
${
command
}
${
remote
}
"
>>
.
${
script
/.sh/.log
}
echo
"
$(
date
)
| ssh
${
command
}
${
remote
}
"
>>
.
${
script
/.sh/.log
}
fi
fi
echo
"Command Log in .
${
script
/.sh/.log
}
"
echo
"Command Log in .
${
script
/.sh/.log
}
"
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment