Question

I know I can create and remove scheduled jobs using the Linux at and atrm commands. Is there a way to get the number of a job at the time at is executed?

atrm needs the job number to remove it. I can think of workarounds like using unique queue names when inserting jobs, then fetching the list of jobs with atq, parsing the lines and finding the one I need so finally the job number can be passed to atrm. But this seems overly complicated.

What I'm looking for is to persist the job number at the time of creation so if I need to remove it, I already have it.

Was it helpful?

Solution

At least my version of at prints the created job number when adding the job, it should be fairly trivial to extract it from there:

$ echo /bin/true | at now + 1hour
warning: commands will be executed using /bin/sh
job 5 at Fri Jun  7 14:13:00 2013
$ echo /bin/true | at now + 1hour 2>&1 | tail -1 | cut -f2 -d" "
6
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top