Computing : Condor Commands: Selections and Formating

job related HTCondor commands like condor_q, condor_history, condor_rm,... support options for a fine-grained selection and printing of the found results.

For example, the command:

condor_q job selection
condor_q -const ' jobstatus==2 && Owner=="FOOUSER" ' -af ClusterID ProcID

selects and prints all running jobs by user "FOOUSER" and print their job IDs (for the job states see http://pages.cs.wisc.edu/~adesmet/status.html - like 1:idle, 2:running, 3:removed, 4:completed, 5:held )

Selection Constraints

The -const flag understands a C-like syntax for combining multiple constraints. In principle, all the class ads of a job can be used in such a query (see `condor_q -l JOB.ID` for the long format of a job information including all its class ads). For more complex queries it might be necessary to escape quotation marks and such...


So, if you want to see all jobs in state running, that have requested a runtime larger than 10801 seconds (logical-)or have requested more than two cores, and have a regular expression matching - and print all the found jobs' IDs as well as the date in epoch seconds, when these jobs were queued, and their log output path

more compelx constraints
condor_q -const 'jobstatus==2 && (Runtime > 10801 || RequestCpus > 2) && regexp("atlas.*", UserLog) ' -af owner ClusterID ProcID QDate UserLog

here as an example, the 'regexp' marco becomes true for all jobs, where the "UserLog" class ad contains the string "atlas" - let's say you want to find your jobs writing their logs to "/foo/mnt/atlas/".  Be aware, that you will also see all jobs that would write their logs to "/home/schmatlasix/log" and such, where the expression matches as well.

Condor provides a number of macros like 'regexp' - see https://htcondor.readthedocs.io/en/latest/misc-concepts/classad-mechanism.html?highlight=regexp#querying-with-classad-expressions

Formating

The easiest formating option is the auto-format "-af" - here you just list the class ads, that you ant to get printed for the matching jobs. In the example above

... -af owner ClusterID ProcID QDate UserLog


the result could look like something as

FOOUSER 9691076 97 1611068310 /home/foouser/log/mylog.9691076.97.log
FOOUSER 9691076 98 1611068313 /home/foouser/log/mylog.9691076.98.log
FOOUSER 9691076 99 1611068317 /home/foouser/log/mylog.9691076.99.log
...


If you want to print the results with your own formatting of choice, you have to use the '-format' flag, that has to be added for each class ad with the intended string formatting. The -format flag takes the string and %s as placeholder for the class ad - e.g.,  -format "your %s string" myclassadd

So selecting all currently running jobs, you could do something like

fancy output formatting
condor_q  -const 'jobstatus==2' -format ">> %s"  ClusterID -format ".%s <<" ProcID  -format " got submitted at %s epoch" QDate -format " and logs to --> %s\n" UserLog

condor_q -const 'jobstatus==2' -format ">> %s" ClusterID  -format ".%s <<" ProcID  -format " got submitted at %s epoch" QDate  -format " and logs to --> %s\n" UserLog

to squeeze the ClusterID, ProcID, QDate and Userlog class ads into strings, that would like

>> 9691076.96 << got submitted at 1611068310 epoch and logs to --> /home/foouser/log/mylog.9691076.96.log
>> 9691077.0 << got submitted at 1611068333 epoch and logs to --> /home/fbazuser/log/plonk.log

Note the newline "\n" ending the last class ad we print here - else the results would end up all in one line.

But probably you would want to play around yourself and print result strings, that are easier to read and parse compared to this example...