Skip to content

Instantly share code, notes, and snippets.

@willfurnass
Created April 9, 2018 12:46
Show Gist options
  • Save willfurnass/8fcfb53ffda2c4dc39f32bb8a2e2d80e to your computer and use it in GitHub Desktop.
Save willfurnass/8fcfb53ffda2c4dc39f32bb8a2e2d80e to your computer and use it in GitHub Desktop.
Grid Engine JSV snippet to reject jobs containing CRLF
#!/usr/bin/tclsh
set sge_root $env(SGE_ROOT)
source "$sge_root/util/resources/jsv/jsv_include.tcl"
proc jsv_on_start {} {
jsv_send_env
}
proc lexists name {
expr {![catch {file lstat $name finfo}]}
}
proc jsv_on_verify {} {
set do_correct 0
set do_wait 0
# ...
# Check for CRLF (windows-style) line endings as they make SGE barf
set crlf "\r\n"
# Get the name of the command that the user wants to run as a job
set cmd [ jsv_get_param CMDNAME ]
set binary [ jsv_get_param b ]
# If we're not dealing with a binary command...
if {$binary != y && $binary != yes} {
# ...but a script file
if [lexists $cmd] {
# Open that script file
set fp [open $cmd r]
# Do not do any on the fly conversion of this file when reading it in Tcl - treat it as a binary file
fconfigure $fp -eofchar "char" -translation binary
# Read in the entire file
set data [read $fp]
close $fp
# Check to see if we can find a CRLF substring in it
if {[string first $crlf $data] != -1} {
jsv_reject "ERROR: Job submission script cannot contain Windows-style (CRLF) line endings; please run dos2unix on it."
return
}
}
}
# ...
if {$do_wait == 1} {
jsv_reject_wait "Job is rejected. It might be submitted later."
} elseif {$do_correct == 1} {
jsv_correct "Job was modified before it was accepted"
} else {
jsv_accept "Job is accepted"
}
}
jsv_main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment