Removing all at jobs except the ones running?
ubuntu-users-list at thomas.freit.ag
ubuntu-users-list at thomas.freit.ag
Mon Mar 7 16:16:09 UTC 2022
Hi Bo,
On 07.03.22 11:50, Bo Berglund wrote:
> $ atq
> 257 Mon Mar 7 19:58:00 2022 a pi
> 260 Mon Mar 7 10:59:00 2022 = pi
> 268 Mon Mar 7 18:59:00 2022 a pi
> 273 Tue Mar 8 00:05:00 2022 a pi
> 267 Mon Mar 7 17:59:00 2022 a pi
> 256 Mon Mar 7 15:58:00 2022 a pi
> 266 Mon Mar 7 16:59:00 2022 a pi
> 264 Mon Mar 7 14:59:00 2022 a pi
> 271 Mon Mar 7 21:59:00 2022 a pi
> 255 Mon Mar 7 11:58:00 2022 a pi
> 263 Mon Mar 7 13:59:00 2022 a pi
> 261 Mon Mar 7 11:59:00 2022 a pi
> 258 Mon Mar 7 23:58:00 2022 a pi
> 265 Mon Mar 7 15:59:00 2022 a pi
> 262 Mon Mar 7 12:59:00 2022 a pi
> 270 Mon Mar 7 20:59:00 2022 a pi
> 272 Mon Mar 7 23:59:00 2022 a pi
> 269 Mon Mar 7 19:59:00 2022 a pi
>
> so now I need a command which will remove what is output from "atq -q =" from
> the output of atq without argument...
Looks like you are only usinq queue "a" (which is the default), easiest approach would be atq -q a to list all those jobs. ;-)
Another approach would be to filter by second last colum, which can be done with awk, this will print column 1 from each line
which has no equal sign in the second last colum:
$ atq | awk '$(NF-1) != "=" { print $1 }'
> I am pretty dumb when dealing with bash scripting, so this is probably over the
> top of me.
[...]
> I tried this in my script atremove but the output is really confusing:
I would assume, that single quotes break something (quotation is tricky), if you run your script with "bash -x", you will get an idea
(comments by me):
+ CMD='atq -q = | cut -f 1'
+ echo 'Cmd: atq -q = | cut -f 1'
Cmd: atq -q = | cut -f 1
++ atq -q = '|' cut -f 1 # pipe is single quoted on execution
atq: invalid option -- 'f'
Usage: at [-V] [-q x] [-f file] [-mMlbv] timespec ...
at [-V] [-q x] [-f file] [-mMlbv] -t time
at -c job ...
atq [-V] [-q x]
at [ -rd ] job ...
atrm [-V] job ...
batch
+ RUNNING= # empty, because above failed
+ echo 'Running: '
Running:
+ eval 'atq | cut -f 1 | grep -v ' # grep is missing an argument due to the empty var
++ atq
++ cut -f 1
++ grep -v
Using "bash -x" is alway a good start for debugging, I would recomment shellcheck as another tool to check your scripts as well.
hth,
Thomas
More information about the ubuntu-users
mailing list