-1

On a cluster using slurm I am trying to create a list of jobs that were submit in a certain time interval so that I can cancel them.

By hand I can do this using:

sacct --format="JobID,Submit"

which will give me a list JobID's and the corresponding of submission times, in the form:

1919614      2019-04-02T19:31:30 
1919615      2019-04-02T19:31:32 
1919616      2019-04-02T19:31:33
1919686      2019-04-02T19:47:29 
1919687      2019-04-02T19:47:30 
1919688      2019-04-02T19:47:32 
1919689      2019-04-02T19:47:33 
1919690      2019-04-02T19:47:35 
1919691      2019-04-02T19:47:36

How do I select JobID's from the first column with date-times in a certain interval in the second column using the command line.

So for example given an interval {2019-04-02T19:47:30,2019-04-02T19:47:33} it should give

1919687
1919688   
1919689

(Or is there a better way to do this altogether.)


I added the awk tag as this question could have been asked without giving any background information on the origin of the string. The question than simply is how to print only the first column if the second column is a date in a certain interval which seems like it should be possible using awk

(I think the background information is important to add in case someone has a better solution using different tools. See XY problem)

Kvothe
  • 233
  • 1
  • 8
  • Should a job be included if it is equal to the start or end of interval? Or only if it is strictly respectively greater and less? – jas Apr 04 '19 at 10:53
  • Give an example interval and show the expected output based on your sample input. – jas Apr 04 '19 at 10:54
  • @jas, I would say yes include it (but it doesn't really matter as long as I know whether it does or not so if not including it is simper for some reason that is fine too). – Kvothe Apr 04 '19 at 11:50

2 Answers2

2

Your date-times are already in an orderable format so you should just be able to:

$ awk '$2 >= "2019-04-02T19:47:30" && $2 <= "2019-04-02T19:47:33" { print $1 }' file
1919687
1919688
1919689

If you want to make it a bit more general:

$ start="2019-04-02T19:47:30"
$ end="2019-04-02T19:47:33"
$ awk -v start=$start -v end=$end '$2 >= start && $2 <= end { print $1 }' file
1919687
1919688
1919689
jas
  • 10,715
  • 2
  • 30
  • 41
0

No need for awk, Slurm's sacct can do the filtering for you:

sacct --state PD --starttime 019-04-02T19:47:30 --endtime 2019-04-02T19:47:33
Keldorn
  • 1,980
  • 15
  • 25