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).
Asked
Active
Viewed 2,753 times
1 Answers
2
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 | awk '/job/ {print $2}'
8
The 2>&1 redirects stderr to stdout so you can manipulate it. The awk returns the second field in the line that has the word "job" in it, which is the line that contains the job id.
So it get it into a variable, you can do:
$ TEST=`at now -f test.sh 2>&1 | awk '/job/ {print $2}'`
$ echo $TEST
9