On 2013-03-05 11:17, Paul Mather wrote:
> On Mar 5, 2013, at 9:54 AM, Dan Langille <[email protected]> wrote:
>
>> On 2013-03-04 04:42, Konstantin Khomoutov wrote:
>>> On Mon, 4 Mar 2013 08:45:05 +0100
>>> Geert Stappers <[email protected]> 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.
Confirmed. I was using FreeBSD 8.2 there. I just tried a 9.1 machine:
$ seq 1 3
1
2
3
$
And from man seq:
HISTORY
The seq command first appeared in Plan 9 from Bell Labs. A seq
command
appeared in NetBSD 3.0, and ported to FreeBSD 9.0. This command
was
based on the command of the same name in Plan 9 from Bell Labs and
the
GNU core utilities. The GNU seq command first appeared in the
1.13 shell
utilities release.
> 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).
Nice!
>
>
>> 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
WOOT!
--
Dan Langille - http://langille.org/
------------------------------------------------------------------------------
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/bacula-users