Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
ssh_scripts
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sofiane Bendoukha
ssh_scripts
Commits
d8429d50
Commit
d8429d50
authored
8 years ago
by
Mathis Rosenhauer
Browse files
Options
Downloads
Patches
Plain Diff
Break lines below 80
parent
0ebc4d62
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
startvnc.sh
+38
-19
38 additions, 19 deletions
startvnc.sh
with
38 additions
and
19 deletions
startvnc.sh
+
38
−
19
View file @
d8429d50
...
...
@@ -16,15 +16,21 @@
set
-e
# User defined variables
USERNAME
=
<user>
# <-- Set here your account number
ACCTCODE
=
<project>
# <-- Set here your project number
TIME
=
240
# <-- Set here the running time in minutes
QOS
=
normal
# <-- Set here an alternative QOS if desired
GEOMETRY
=
${
1
:-
'1920x1200'
}
# <-- Set here the resolution of your remote desktop window
VNCVIEWER
=
/usr/bin/vncviewer
# <-- Set here the correct path to your local vncviewer, i.e. TightVNC
PASSWORD
=
true
# <-- If enabled, the vncpassword will be temporarily copied to the local workstation (only works with TurboVNC)
# End of user defined variables
TIME
=
240
# <-- Set here the running time in
# minutes
QOS
=
normal
# <-- Set here an alternative QOS
# if desired
GEOMETRY
=
${
1
:-
'1920x1200'
}
# <-- Set here the resolution of
# your remote desktop window
VNCVIEWER
=
/usr/bin/vncviewer
# <-- Set here the correct path to
# your local vncviewer, e.g.
# TurboVNC
PASSWORD
=
true
# <-- If enabled, the vncpassword
# will be temporarily copied to
# the local workstation (only
# works with TurboVNC)
clean_up
()
{
trap
- ERR
...
...
@@ -38,20 +44,24 @@ clean_up () {
if
[[
${
vnc_host_display
}
&&
${
xvnc_pid
}
]]
;
then
# Kill Xvnc process. Mainly done to remove lock file.
local
vnc_host
=
$(
echo
${
vnc_host_display
}
|
cut
-d
':'
-f1
)
ssh
${
USERNAME
}
@mistral.dkrz.de
"ssh
${
USERNAME
}
@
${
vnc_host
}
\"
kill
${
xvnc_pid
}
\"
"
2> /dev/null
ssh
${
USERNAME
}
@mistral.dkrz.de
\
"ssh
${
USERNAME
}
@
${
vnc_host
}
\"
kill
${
xvnc_pid
}
\"
"
2> /dev/null
fi
if
[[
${
job_id
}
]]
;
then
# Clean up temp files and cancel job
tmp_files
=
"
${
tmp_files
}
out.
${
job_id
}
out.
${
job_id
}
_DKRZepilog vnc_gethost.
${
job_id
}
"
ssh
${
USERNAME
}
@mistral.dkrz.de
"scancel
${
job_id
}
; sleep 1"
2> /dev/null
tmp_files
=
"
${
tmp_files
}
out.
${
job_id
}
out.
${
job_id
}
_DKRZepilog
\
vnc_gethost.
${
job_id
}
"
ssh
${
USERNAME
}
@mistral.dkrz.de
\
"scancel
${
job_id
}
; sleep 1"
2> /dev/null
else
echo
"Job ID not available. Make sure the vncjob is not running!"
ssh
${
USERNAME
}
@mistral.dkrz.de
"squeue -u
${
USERNAME
}
"
fi
if
[[
${
tmp_files
}
]]
;
then
ssh
${
USERNAME
}
@mistral.dkrz.de
"cd .startvnc && rm -f
${
tmp_files
}
"
2> /dev/null
ssh
${
USERNAME
}
@mistral.dkrz.de
\
"cd .startvnc && rm -f
${
tmp_files
}
"
2> /dev/null
fi
# Remove local vnc PasswordFile
...
...
@@ -61,10 +71,13 @@ clean_up () {
exit
}
trap
'clean_up "${job_id}" "${vnc_host_display}" "${xvnc_pid}" "${job_script}"'
INT QUIT TERM ERR
trap
'clean_up \"${job_id}\" \"${vnc_host_display}\" \"${xvnc_pid}\" \
\"${job_script}\"'
INT QUIT TERM ERR
job_script
=
$(
ssh
${
USERNAME
}
@mistral.dkrz.de
'mkdir -p .startvnc && cd .startvnc && mktemp vncjob.XXXXX'
)
ssh
${
USERNAME
}
@mistral.dkrz.de
"mkdir -p .startvnc; cat > .startvnc/
${
job_script
}
"
<<
EOF
job_script
=
$(
ssh
${
USERNAME
}
@mistral.dkrz.de
\
'mkdir -p .startvnc && cd .startvnc && mktemp vncjob.XXXXX'
)
ssh
${
USERNAME
}
@mistral.dkrz.de
\
"mkdir -p .startvnc; cat > .startvnc/
${
job_script
}
"
<<
EOF
#!/bin/bash
#SBATCH --partition=gpu
#SBATCH --ntasks=12
...
...
@@ -78,7 +91,8 @@ cd \${HOME}
EOF
echo
"Submitting Xvnc job."
job_id
=
$(
ssh
${
USERNAME
}
@mistral.dkrz.de
"cd .startvnc && sbatch
${
job_script
}
"
|
grep
-Po
"
\b
[0-9]+$"
)
job_id
=
$(
ssh
${
USERNAME
}
@mistral.dkrz.de
\
"cd .startvnc && sbatch
${
job_script
}
"
|
grep
-Po
"
\b
[0-9]+$"
)
ssh
${
USERNAME
}
@mistral.dkrz.de
"cat > .startvnc/vnc_gethost.
${
job_id
}
"
<<
EOF
#!/bin/bash
...
...
@@ -87,19 +101,24 @@ LOGFILE=out.${job_id}
while [ -z
\$
{vnc_host_display} ]; do
sleep 1
if [[ -f
\$
{LOGFILE} ]]; then
vnc_host_display=
\$
(grep -Po "started on display
\K
mg[0-9]+:[0-9]+"
\$
{LOGFILE})
vnc_host_display=
\$
(grep -Po "started on display
\K
mg[0-9]+:[0-9]+"
\
\$
{LOGFILE})
fi
done
echo
\$
{vnc_host_display}
EOF
echo
"Waiting for job
${
job_id
}
to start."
vnc_host_display
=
$(
ssh
${
USERNAME
}
@mistral.dkrz.de
"/bin/bash .startvnc/vnc_gethost.
${
job_id
}
"
)
xvnc_pid
=
$(
ssh
${
USERNAME
}
@mistral.dkrz.de
"cat .vnc/
${
vnc_host_display
}
.pid"
)
vnc_host_display
=
$(
ssh
${
USERNAME
}
@mistral.dkrz.de
\
"/bin/bash .startvnc/vnc_gethost.
${
job_id
}
"
)
xvnc_pid
=
$(
ssh
${
USERNAME
}
@mistral.dkrz.de
\
"cat .vnc/
${
vnc_host_display
}
.pid"
)
# Start VNC client
if
[[
${
PASSWORD
}
==
true
]]
;
then
scp
${
USERNAME
}
@mistral.dkrz.de:~/.vnc/passwd ~/.vnc/passwd2
${
VNCVIEWER
}
-via
${
USERNAME
}
@mistral.dkrz.de
${
vnc_host_display
}
-PasswordFile
~/.vnc/passwd2
${
VNCVIEWER
}
-via
${
USERNAME
}
@mistral.dkrz.de
${
vnc_host_display
}
\
-PasswordFile
~/.vnc/passwd2
else
${
VNCVIEWER
}
-via
${
USERNAME
}
@mistral.dkrz.de
${
vnc_host_display
}
fi
...
...
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