Re: singleton for script with shebang
That would work. Does --semaphoretimeout 0 mean never give up? If so then -0 could mean give up immediately. By the way the note on the sem man page says that sem --timeout is not implemented. --timeout secs (not implemented) -t secs (not implemented) If the semaphore is not released within secs seconds, take itanyway. And indeed testing of (parallel --version \n GNU parallel 20141022) indicate that it does not work. Anyway great product, thanks Ole. Bradley On Fri, Jan 2, 2015 at 7:35 AM, Ole Tange wrote: > On Fri, Jan 2, 2015 at 10:51 AM, Bradley Asztalos > wrote: > > > Taking this one step further, I know of course there are other ways to do > > this, but what about a way to have sem die if it cannot immediately > acquire > > execute? Something like --die_young so that it could be used not only to > > serialize but to disallow a run if there is already a process running > with > > the same lock_id. > > So that is almost the opposite of --semaphoretimeout > > Maybe it should be able to take a negative value: If you cannot get > the semaphore within 2 seconds, give up. > > sem --semaphoretimeout -2 do_stuff > > > /Ole >
Re: singleton for script with shebang
On Fri, Jan 2, 2015 at 10:51 AM, Bradley Asztalos wrote: > Taking this one step further, I know of course there are other ways to do > this, but what about a way to have sem die if it cannot immediately acquire > execute? Something like --die_young so that it could be used not only to > serialize but to disallow a run if there is already a process running with > the same lock_id. So that is almost the opposite of --semaphoretimeout Maybe it should be able to take a negative value: If you cannot get the semaphore within 2 seconds, give up. sem --semaphoretimeout -2 do_stuff /Ole
Re: singleton for script with shebang
On Fri, Jan 2, 2015 at 11:07 AM, Bradley Asztalos wrote: > No, I did not say anything about Shlomi being right, That was me asking a rhetorical question. I should stop doing that, as that is easy to misunderstand in writing. I should instead have written: Slomi is right in certain circumstances. /Ole
Re: singleton for script with shebang
Ole, No problem, I realized that it was rhetorical after I wrote the response. Cheers Shlomi and Ole and thank you for the help. Cheers, Bradley On Fri, Jan 2, 2015 at 2:15 AM, Ole Tange wrote: > On Fri, Jan 2, 2015 at 11:07 AM, Bradley Asztalos > wrote: > > > No, I did not say anything about Shlomi being right, > > That was me asking a rhetorical question. I should stop doing that, as > that is easy to misunderstand in writing. > > I should instead have written: Slomi is right in certain circumstances. > > > /Ole >
Re: singleton for script with shebang
And yes I'm aware of the problems with shebang length and also the difference between being able to call an interpreter from shebang on different Unixes. Cheers, Bradley On Fri, Jan 2, 2015 at 2:07 AM, Bradley Asztalos wrote: > Ole, > > No, I did not say anything about Shlomi being right, just that you are > clever, in the good sense. To me it is great to be able to use shebang, and > it is not overly "clever" at all, in the bad sense. I often use the > /usr/bin/timeout command and parallel + a command + arguments in crontab > entries and other shell scripts and that gets unwieldy, so it is rather > nice to be able to use shebang to encapsulate at least the parallel part of > the command line. > > Cheers, > > Bradley > > On Fri, Jan 2, 2015 at 1:55 AM, Ole Tange wrote: > >> On Fri, Jan 2, 2015 at 8:14 AM, Shlomi Fish >> wrote: >> > On Thu, 1 Jan 2015 13:54:57 -0800 >> > Bradley Asztalos wrote: >> : >> >> [... shebang ...] >> > >> > parallel is written in Perl 5 and uses «#!/usr/bin/perl» or whatever as >> a >> > shebang. As a result it cannot be itself used as a she-bang processor. >> >> So why is Shlomi right, when it is clearly possible to use GNU >> Parallel as shebang program? >> >> It is because on some UNIX systems this is actually true. On FreeBSD >> you need to do: >> >> #!/usr/bin/env -S parallel --shebang-wrap ... >> >> On other UNIXes there is no work around. >> >> > Furthermore, I should note that in programming, it is a good idea to >> stick to >> > the https://en.wikipedia.org/wiki/KISS_principle and not try to be as >> clever as >> > possible. >> >> Sometimes the code is simpler if GNU Parallel is put in the shebang >> line. But it does carry some limitations. The length of the shebang >> line is quite limited on many systems, and often the systems will >> simply chop it off without any warning. >> >> See http://www.in-ulm.de/~mascheck/various/shebang/#length >> >> >> /Ole >> >> >
Re: singleton for script with shebang
Ole, No, I did not say anything about Shlomi being right, just that you are clever, in the good sense. To me it is great to be able to use shebang, and it is not overly "clever" at all, in the bad sense. I often use the /usr/bin/timeout command and parallel + a command + arguments in crontab entries and other shell scripts and that gets unwieldy, so it is rather nice to be able to use shebang to encapsulate at least the parallel part of the command line. Cheers, Bradley On Fri, Jan 2, 2015 at 1:55 AM, Ole Tange wrote: > On Fri, Jan 2, 2015 at 8:14 AM, Shlomi Fish > wrote: > > On Thu, 1 Jan 2015 13:54:57 -0800 > > Bradley Asztalos wrote: > : > >> [... shebang ...] > > > > parallel is written in Perl 5 and uses «#!/usr/bin/perl» or whatever as a > > shebang. As a result it cannot be itself used as a she-bang processor. > > So why is Shlomi right, when it is clearly possible to use GNU > Parallel as shebang program? > > It is because on some UNIX systems this is actually true. On FreeBSD > you need to do: > > #!/usr/bin/env -S parallel --shebang-wrap ... > > On other UNIXes there is no work around. > > > Furthermore, I should note that in programming, it is a good idea to > stick to > > the https://en.wikipedia.org/wiki/KISS_principle and not try to be as > clever as > > possible. > > Sometimes the code is simpler if GNU Parallel is put in the shebang > line. But it does carry some limitations. The length of the shebang > line is quite limited on many systems, and often the systems will > simply chop it off without any warning. > > See http://www.in-ulm.de/~mascheck/various/shebang/#length > > > /Ole > >
Re: singleton for script with shebang
On Fri, Jan 2, 2015 at 8:14 AM, Shlomi Fish wrote: > On Thu, 1 Jan 2015 13:54:57 -0800 > Bradley Asztalos wrote: : >> [... shebang ...] > > parallel is written in Perl 5 and uses «#!/usr/bin/perl» or whatever as a > shebang. As a result it cannot be itself used as a she-bang processor. So why is Shlomi right, when it is clearly possible to use GNU Parallel as shebang program? It is because on some UNIX systems this is actually true. On FreeBSD you need to do: #!/usr/bin/env -S parallel --shebang-wrap ... On other UNIXes there is no work around. > Furthermore, I should note that in programming, it is a good idea to stick to > the https://en.wikipedia.org/wiki/KISS_principle and not try to be as clever > as > possible. Sometimes the code is simpler if GNU Parallel is put in the shebang line. But it does carry some limitations. The length of the shebang line is quite limited on many systems, and often the systems will simply chop it off without any warning. See http://www.in-ulm.de/~mascheck/various/shebang/#length /Ole
Re: singleton for script with shebang
Ole, Taking this one step further, I know of course there are other ways to do this, but what about a way to have sem die if it cannot immediately acquire execute? Something like *--die_young* so that it could be used not only to serialize but to disallow a run if there is already a process running with the same lock_id. #!/usr/bin/parallel --shebang-wrap --semaphore --fg -u --id lock_id *--die_young* /bin/bash echo "enter"$ exec sleep 5 echo "exit"$ Thanks again for your great work! Cheers, Bradley On Fri, Jan 2, 2015 at 1:44 AM, Bradley Asztalos wrote: > Ole, > > Thank you for the great product. It's a joy to use and thank you for > administering the forum so well. > > Cheers, > > Bradley Asztalos > > On Fri, Jan 2, 2015 at 1:29 AM, Bradley wrote: > >> Agreed "Doh!" >> >> >> >> > On Jan 2, 27 Heisei, at 12:48 AM, Ole Tange wrote: >> > >> > On Thu, Jan 1, 2015 at 10:54 PM, Bradley Asztalos >> > wrote: >> > >> >> But I'm wondering if it is possible to use shebang in this context as >> in: >> > >> > It is. >> > >> >> ---singleton.sh- >> >> >> >> #!/opt/local/bin/parallel --shebang-wrap /bin/bash --semaphore --fg -u >> --id >> >> lock_id >> >> echo "start" $$ >> >> sleep 10 >> >> echo "end" $$ >> >> >> >> - >> >> >> >> This does not work. Any ideas here? >> > >> > You are going to say 'Doh'. >> > >> > /bin/bash is not an argument for --shebang-wrap. It is the command you >> > want to be run. Also --semaphore --fg -u --id are not options for >> > bash. Swap them around and you are good: >> > >> > #!/opt/local/bin/parallel --shebang-wrap --semaphore --fg -u --id >> > lock_id /bin/bash >> > >> > (Here is where you say 'Doh'). >> > >> > >> > /Ole >> > >
Re: singleton for script with shebang
Ole, Thank you for the great product. It's a joy to use and thank you for administering the forum so well. Cheers, Bradley Asztalos On Fri, Jan 2, 2015 at 1:29 AM, Bradley wrote: > Agreed "Doh!" > > > > > On Jan 2, 27 Heisei, at 12:48 AM, Ole Tange wrote: > > > > On Thu, Jan 1, 2015 at 10:54 PM, Bradley Asztalos > > wrote: > > > >> But I'm wondering if it is possible to use shebang in this context as > in: > > > > It is. > > > >> ---singleton.sh- > >> > >> #!/opt/local/bin/parallel --shebang-wrap /bin/bash --semaphore --fg -u > --id > >> lock_id > >> echo "start" $$ > >> sleep 10 > >> echo "end" $$ > >> > >> - > >> > >> This does not work. Any ideas here? > > > > You are going to say 'Doh'. > > > > /bin/bash is not an argument for --shebang-wrap. It is the command you > > want to be run. Also --semaphore --fg -u --id are not options for > > bash. Swap them around and you are good: > > > > #!/opt/local/bin/parallel --shebang-wrap --semaphore --fg -u --id > > lock_id /bin/bash > > > > (Here is where you say 'Doh'). > > > > > > /Ole >
Re: singleton for script with shebang
Thanks for the reply, see ole's clever response > On Jan 1, 27 Heisei, at 11:14 PM, Shlomi Fish wrote: > > Hi Bradley, > > On Thu, 1 Jan 2015 13:54:57 -0800 > Bradley Asztalos wrote: > >> I have a simple script, foo.sh:: >> >> #!/bin/bash >> echo "start" $$ >> sleep 10 >> echo "end" $$ >> >> I can run make sure this runs as a singleton with >> >> sem --fg -u --id lock_id ./foo.sh >> >> But I'm wondering if it is possible to use shebang in this context as in: >> >> ---singleton.sh- >> >> #!/opt/local/bin/parallel --shebang-wrap /bin/bash --semaphore --fg -u --id >> lock_id >> echo "start" $$ >> sleep 10 >> echo "end" $$ >> >> - > > parallel is written in Perl 5 and uses «#!/usr/bin/perl» or whatever as a > shebang. As a result it cannot be itself used as a she-bang processor. > Furthermore, I should note that in programming, it is a good idea to stick to > the https://en.wikipedia.org/wiki/KISS_principle and not try to be as clever > as > possible. > > Hope it helps. > > Regards, > >Shlomi Fish > >> This does not work. Any ideas here? >> >> Bradley > > > > -- > - > Shlomi Fish http://www.shlomifish.org/ > The Human Hacking Field Guide - http://shlom.in/hhfg > > A kid always wishes they were older until they are 18. Afterwards, they always > wish they were younger. > > Please reply to list if it's a mailing list post - http://shlom.in/reply . >
Re: singleton for script with shebang
Agreed "Doh!" > On Jan 2, 27 Heisei, at 12:48 AM, Ole Tange wrote: > > On Thu, Jan 1, 2015 at 10:54 PM, Bradley Asztalos > wrote: > >> But I'm wondering if it is possible to use shebang in this context as in: > > It is. > >> ---singleton.sh- >> >> #!/opt/local/bin/parallel --shebang-wrap /bin/bash --semaphore --fg -u --id >> lock_id >> echo "start" $$ >> sleep 10 >> echo "end" $$ >> >> - >> >> This does not work. Any ideas here? > > You are going to say 'Doh'. > > /bin/bash is not an argument for --shebang-wrap. It is the command you > want to be run. Also --semaphore --fg -u --id are not options for > bash. Swap them around and you are good: > > #!/opt/local/bin/parallel --shebang-wrap --semaphore --fg -u --id > lock_id /bin/bash > > (Here is where you say 'Doh'). > > > /Ole
Re: singleton for script with shebang
On Thu, Jan 1, 2015 at 10:54 PM, Bradley Asztalos wrote: > But I'm wondering if it is possible to use shebang in this context as in: It is. > ---singleton.sh- > > #!/opt/local/bin/parallel --shebang-wrap /bin/bash --semaphore --fg -u --id > lock_id > echo "start" $$ > sleep 10 > echo "end" $$ > > - > > This does not work. Any ideas here? You are going to say 'Doh'. /bin/bash is not an argument for --shebang-wrap. It is the command you want to be run. Also --semaphore --fg -u --id are not options for bash. Swap them around and you are good: #!/opt/local/bin/parallel --shebang-wrap --semaphore --fg -u --id lock_id /bin/bash (Here is where you say 'Doh'). /Ole