On Mar 5, 2013, at 9:54 AM, Dan Langille <dan AT langille DOT org> wrote:
> On 2013-03-04 04:42, Konstantin Khomoutov wrote:
>> On Mon, 4 Mar 2013 08:45:05 +0100
>> Geert Stappers <Geert.Stappers AT vanadgroup DOT com> wrote:
>>
>> [...]
>>> Thank you for the tip. I want to share another.
>>> It is about canceling multiple jobs. Execute from shell
>>>
>>> for i in {17..21} ; do echo cancel yes jobid=404${i} | bconsole ;
>>> done
>>>
>>> Five jobs, 40417-40421, will be canceled.
>>
>> A minor nitpick: the construct
>>
>> for i in {17..21}; do ...
>>
>> is a bashism [1], so it won't work in any POSIX shell.
>
> A good point! I tried the above on FreeBSD:
>
> $ cat test.sh
> #!/bin/sh
>
> for i in {17..21} ; do echo cancel yes jobid=404${i} ; done
>
>
> [dan@bast:~/bin] $ ./sh test.sh
> cancel yes jobid=404{17..21}
> [dan@bast:~/bin] $
>
>>
>> A portable way to do the same is to use the `seq` program
>>
>> for i in `seq 17 21`; do ...
>>
>> or to maintain an explicit counter:
>>
>> i=17
>> while [ $i -le 21 ]; do ...; i=$(($i+1)); done
>
> Then I tried this approach but didn't find seq at all. I tried sh,
> csh, and tcsh.
Seq appeared in FreeBSD 9, so if you tried it in earlier versions that's
probably why you didn't find it.
Using seq, you might have to use "-f %02g" to get two-digit sequences with
leading zeros (or "-f %0Ng" to get N-digit sequences with leading zeros).
> But I know about jot. This does 5 numbers, starting at 17:
>
> $ jot 5 17
> 17
> 18
> 19
> 20
> 21
>
> Thus, the script becomes:
>
> $ cat test.sh
> #!/bin/sh
>
> for i in `jot 5 17` ; do echo cancel yes jobid=404${i} ; done
>
>
> $ sh ./test.sh
> cancel yes jobid=40417
> cancel yes jobid=40418
> cancel yes jobid=40419
> cancel yes jobid=40420
> cancel yes jobid=40421
With jot you can shorten this even further:
jot -w "cancel yes jobid=404%g" 5 17
Again, you might want to zero-pad if you are cancelling, say, jobs 40405 to
40423:
jot -w "cancel yes jobid=404%02g" 19 5
Or, better yet, just start from the job range beginning itself:
jot -w "cancel yes jobid=%g" 19 40405
Cheers,
Paul.
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_feb
_______________________________________________
Bacula-users mailing list
Bacula-users AT lists.sourceforge DOT net
https://lists.sourceforge.net/lists/listinfo/bacula-users
|