Tell me more ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Is it possible to have the at command return somehow the job id it just submitted when used from within a script? (kind of like $? retrieves the last exit code or $$/$! retrieve the PID of the command just executed).

share|improve this question
When I run echo "touch foo" | at now, I get e.g. job 3 at Thu Dec 15 17:14:52 2011 as output — you don't? Likewise inside a script, it writes to standard output, from where it can be parsed. – Daniel Beck Dec 15 '11 at 16:16

1 Answer

up vote 1 down vote accepted

Assuming that the job you want to run is in a file called test.sh, the following will return the id:

 $ at now -f test.sh 2>&1 | grep job | awk '{print $2}'
 8

The 2>&1 redirects stderr to stdout so you can manipulate it. The grep gets the job line. The awk returns the second field in the line found by grep, which contains the job id.

So it get it into a variable, you can do:

$ TEST=`at now -f test.sh 2>&1 | grep job | awk '{print $2}'`
$ echo $TEST
9
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.