1

I've been using at to schedule emails to be sent at a specific date and time. Problem is that the command that I wish at to execute should take the job id as a parameter hence why I should be the one generating them. This is aside from the fact that what at uses aren't id's at all, rather counts that gets incremented automatically which means that I have to worry about when they will reset.

My main inquiry is creating new at jobs with custom id's. Meaning that while creating jobs with the following command: echo "touch file" | at now + 1 minute, if it could instead be something like this: echo "touch file" | at -i <custom-id> now + 1 minute. So that when I hit atq, I will find: <custom-id> Mon Feb 24 19:00:00 2020 a user.

So, is there a way to give jobs custom when I create them with at OR if there are any open source alternatives that scale better?

7
  • 1
    I'm sorry Joe I don't understand what it is that you're trying to achieve here. Why doesn't at scale for you? Feb 24, 2020 at 17:22
  • FreeBSD code has jobno = (1+jobno) % 0xfffff; /* 2^20 jobs enough? */, which allows for approximately one million concurrently queued jobs. Feb 24, 2020 at 17:26
  • My main inquiry is creating new at jobs with custom id's. Meaning that while creating jobs with the following command: echo "touch file" | at now + 1 minute, if it could instead be something like this: echo "touch file" | at -i <custom-id> now + 1 minute. So that when I hit atq, I will find: <custom-id> Mon Feb 24 19:00:00 2020 a user.
    – Joe
    Feb 24, 2020 at 18:03
  • As for the scalability of at, it's true that it supports a large number of simultaneous jobs but if what if those jobs are resource heavy, it could potentially lead to the low availability of the server, not to mention that at lacks a ton of features. What if I wanted to delete jobs? I would need to have the id of said job which is a pain to obtain (recovering it from the warning generated by the above command seems kinda hacky). I now need to have the id before I launch the command which looks impossible after a day of reading the docs and searching around.
    – Joe
    Feb 24, 2020 at 18:07
  • I also would like some error handling to schedule another job in case of a network outage.
    – Joe
    Feb 24, 2020 at 18:08

1 Answer 1

0

You can get the job number for an at submission with this sort of code. The example submits a job that simply sleeps for five minutes, so you will obviously have to adjust that. The output from an at submission is like job 1175 at Mon Feb 24 18:28:00 2020 and the grep command matches on this to extract the job number

job=$( echo "sleep 300" | at now 2>&1 | grep -oP 'job\s+\K\d+' )
echo "The job identifier is $job"

There is no way to identify the job number before it has been submitted to at.

2
  • Are there any third-party open-source tools that does the same as at but offer at least the features that I mentioned: create jobs with custom id's (preferably on that integrates with a database like mysql) and error handling in case the scheduled command failed or if the server experienced a downtime during the time a batch of jobs where suppose to be executed.
    – Joe
    Feb 24, 2020 at 19:36
  • I don't know of any. What would you want to happen if a server went down - consider queued jobs and jobs that are currently executing Feb 24, 2020 at 20:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .