euglug.org

[카테고리:] Uncategorized

  • [Eug-lug] Shell script question



    Quentin HartmanTue Aug 1 20:55:13 PDT 2006

    > Or use
    >
    > killall -g $(head -1 /var/run/foo.pid)
    
    
    nice.... (killall -g)++
    
    heh
    
    it was funnier in my head.
    
    -- 
    -Regards-
    
    -Quentin Hartman-
    
  • [Eug-lug] Shell script question



    Fred JamesTue Aug 1 20:26:48 PDT 2006

    Patrick R. Wade wrote:
    
    >A shell script runs a for loop iterating a command:
    >
    >#!/bin/sh
    ># foo.sh ; an example script
    >
    >for i in foo bar baz
    >	do find /home/$i
    >	done
    >
    >exit 0
    >
    >If we run this and observe top, we will see three processes; one for
    >foo.sh, another for a child foo.sh (the for loop) and one for find.
    >
    >If i send a kill to the parent foo.sh process, the child foo.sh and find
    >jobs will continue running.  This, from what i gather, is normal *NIX
    >behavior.  My objective, however, is to ensure that foo.sh exits by a
    >certain time, so i have an at job waiting to send it a kill.  Is there
    >an idiom when writing the script to ensure that the kill it receives
    >will kill the child processes as well?  Is there a completely different
    >approach i need to take when the design requirement of termination by a
    >time certain is added?  Exhortations to learn Python are perhaps apropos
    >but useless in the short term.
    >
    >  
    >
    Patrick R. Wade
    Look into both killall, and fuser, and see if either of those two will 
    help you.  YMMV
    Regard
    Fred James
    
    
  • [Eug-lug] Shell script question



    larry priceTue Aug 1 19:51:38 PDT 2006

    Or use
    
    killall -g $(head -1 /var/run/foo.pid)
    
    after saving the pid as quentin describes.
    
    note: killall varies considerably from platform to platform
    check your man page
    
    
    On 8/1/06, Quentin Hartman <qhartman at gmail.com> wrote:
    > On 8/1/06, Quentin Hartman <qhartman at gmail.com> wrote:
    > > I seem to remember some bash convention that would allow the behavior
    > > you are looking for, but I can't recall exactly what it is. I'm likely
    > > dreaming. My suggestion would be to track the PIDs of the processes
    > > you spawn, which I believe can be done by examining the !$ environment
    > > variable after launching each process, and then killing them
    > > explicitly. I've not had a need to do this myself though, so you'll
    > > have to look elsewhere for specific recommendations on how precisely
    > > this might be done.
    >
    > oops, here's a better idea. Record the PID of the script using $$, and
    > the in your time killer, use that to call "ps --ppid $saved_pid" which
    > will return the PID's of all the children of your script. A little awk
    > slicing and you can kill them each directly.
    >
    > --
    > -Regards-
    >
    > -Quentin Hartman-
    > _______________________________________________
    > EUGLUG mailing list
    > euglug at euglug.org
    > http://www.euglug.org/mailman/listinfo/euglug
    >
    
  • [Eug-lug] Shell script question



    Quentin HartmanTue Aug 1 18:37:45 PDT 2006

    On 8/1/06, Quentin Hartman <qhartman at gmail.com> wrote:
    > I seem to remember some bash convention that would allow the behavior
    > you are looking for, but I can't recall exactly what it is. I'm likely
    > dreaming. My suggestion would be to track the PIDs of the processes
    > you spawn, which I believe can be done by examining the !$ environment
    > variable after launching each process, and then killing them
    > explicitly. I've not had a need to do this myself though, so you'll
    > have to look elsewhere for specific recommendations on how precisely
    > this might be done.
    
    oops, here's a better idea. Record the PID of the script using $$, and
    the in your time killer, use that to call "ps --ppid $saved_pid" which
    will return the PID's of all the children of your script. A little awk
    slicing and you can kill them each directly.
    
    -- 
    -Regards-
    
    -Quentin Hartman-
    
  • [Eug-lug] Shell script question



    Quentin HartmanTue Aug 1 18:23:49 PDT 2006

    On 8/1/06, Patrick R. Wade <prwade at oip.net> wrote:
    > If i send a kill to the parent foo.sh process, the child foo.sh and find
    > jobs will continue running.  This, from what i gather, is normal *NIX
    > behavior.  My objective, however, is to ensure that foo.sh exits by a
    > certain time, so i have an at job waiting to send it a kill.  Is there
    > an idiom when writing the script to ensure that the kill it receives
    > will kill the child processes as well?  Is there a completely different
    > approach i need to take when the design requirement of termination by a
    > time certain is added?
    
    I seem to remember some bash convention that would allow the behavior
    you are looking for, but I can't recall exactly what it is. I'm likely
    dreaming. My suggestion would be to track the PIDs of the processes
    you spawn, which I believe can be done by examining the !$ environment
    variable after launching each process, and then killing them
    explicitly. I've not had a need to do this myself though, so you'll
    have to look elsewhere for specific recommendations on how precisely
    this might be done.
    
    -- 
    -Regards-
    
    -Quentin Hartman-
    
  • [Eug-lug] Shell script question



    larry priceTue Aug 1 16:52:09 PDT 2006

    On 8/1/06, Patrick R. Wade <prwade at oip.net> wrote:
    > A shell script runs a for loop iterating a command:
    >
    > #!/bin/sh
    > # foo.sh ; an example script
    >
    > for i in foo bar baz
    >         do find /home/$i
    >         done
    >
    > exit 0
    >
    > If we run this and observe top, we will see three processes; one for
    > foo.sh, another for a child foo.sh (the for loop) and one for find.
    >
    > If i send a kill to the parent foo.sh process, the child foo.sh and find
    > jobs will continue running.  This, from what i gather, is normal *NIX
    > behavior.  My objective, however, is to ensure that foo.sh exits by a
    > certain time, so i have an at job waiting to send it a kill.  Is there
    > an idiom when writing the script to ensure that the kill it receives
    > will kill the child processes as well?  Is there a completely different
    > approach i need to take when the design requirement of termination by a
    > time certain is added?  Exhortations to learn Python are perhaps apropos
    > but useless in the short term.
    
    are you on a machine that supports pkill ?
    
    python is wonderful but shell scripts are sometimes simpler.
    
  • [Eug-lug] Shell script question



    Patrick R. WadeTue Aug 1 16:34:38 PDT 2006

    A shell script runs a for loop iterating a command:
    
    #!/bin/sh
    # foo.sh ; an example script
    
    for i in foo bar baz
    	do find /home/$i
    	done
    
    exit 0
    
    If we run this and observe top, we will see three processes; one for
    foo.sh, another for a child foo.sh (the for loop) and one for find.
    
    If i send a kill to the parent foo.sh process, the child foo.sh and find
    jobs will continue running.  This, from what i gather, is normal *NIX
    behavior.  My objective, however, is to ensure that foo.sh exits by a
    certain time, so i have an at job waiting to send it a kill.  Is there
    an idiom when writing the script to ensure that the kill it receives
    will kill the child processes as well?  Is there a completely different
    approach i need to take when the design requirement of termination by a
    time certain is added?  Exhortations to learn Python are perhaps apropos
    but useless in the short term.
    
    -- 
    On two occasions I have been asked [by members of Parliament!], 'Pray,
    Mr. Babbage, if you put into the machine wrong figures, will the right
    answers come out?' I am not able rightly to apprehend the kind of
    confusion of ideas that could provoke such a question.
    	-- Charles Babbage
    
  • [Eug-lug] Linux- Mac OS X file exchange: This sounds right



    T. Joseph CarterTue Aug 1 13:43:08 PDT 2006

    On Tue, Aug 01, 2006 at 11:18:53AM -0700, Allen Brown wrote:
    > >suidperl is a thing that lets you run perl scripts setuid.  Normally you
    > >can't do that anymore than you can run a shell script that way.  suidperl
    > >is a workaround to make that possible.  It's an evil thing, you don't want
    > >it, ever.  In fact, I suggest if you're concerned, edit your dpkg status
    > >file and create a fake entry claiming to be suidperl with a version like
    > >7:0.0.0 and no files associated with it or anything.
    > 
    > This doesn't feel right.  Are you sure this is secure and won't
    > break something else?
    > 
    > Looking at the dpkg(8) man page I see mention of "hold"
    >   A package marked to be on hold is not handled by dpkg, unless
    >   forced to do that with option --force-hold.
    
    hold doesn't affect uninstalled packages.  However, it seems that the
    suidperl problem is resolved for you if Ubuntu's solution to the problem
    comes from Debian.  A non-setuid suidperl effectively does nothing.
    
    
    > That sounds closer to what we should be using.  Basically it
    > appears to be a hook in dpkg to lock up a package.  Have I
    > interpreted its description correctly?
    
    It has to be installed first.  There is theoretically a possibility that
    perl's version could change such that it has an epoch of 7 or higher, but
    this is a bit unlikely.  What I described is not far from what an old
    package called equivs did--install an empty "fake" package.  This was done
    in the days before Debian had packaged the entire world to allow dpkg to
    believe a given package was installed from deb when it was in fact
    installed by you.
    
    It's a slightly cleaner way of doing the standard RPM installation
    instruction of forcing no dependency checking.  Cleaner because instead of
    telling dpkg to ignore dependencies (which you can do if you're fool
    enough to do so), you are telling dpkg precisely what dependencies are met
    on your system outside the scope of the package manager.
    
    Nowadays you just apt-get source <thing>, modify as you like, and then
    debuild -us -uc the result.  Back in the days of dpkg -BORGiE, you could
    not so easily do that.
    
    
  • [Eug-lug] Linux- Mac OS X file exchange: This sounds right



    Allen BrownTue Aug 1 11:18:53 PDT 2006

    T. Joseph Carter wrote:
    > On Mon, Jul 31, 2006 at 09:48:46PM -0700, Allen Brown wrote:
    > 
    >>It is tempting to also use nosuid, but there is a warning on
    >>the mount page.
    >>  nosuid Do  not allow set-user-identifier or set-group-identifier
    >>         bits to take effect. (This seems safe,  but  is  in  fact
    >>         rather unsafe if you have suidperl(1) installed.)
    >>
    >>What the heck is that?  I don't seem to have it installed,
    >>but this makes me nervous because I wouldn't necessarily
    >>notice if it came in along with a bunch of other stuff
    >>in an apt-get.
    > 
    > 
    > suidperl is a thing that lets you run perl scripts setuid.  Normally you
    > can't do that anymore than you can run a shell script that way.  suidperl
    > is a workaround to make that possible.  It's an evil thing, you don't want
    > it, ever.  In fact, I suggest if you're concerned, edit your dpkg status
    > file and create a fake entry claiming to be suidperl with a version like
    > 7:0.0.0 and no files associated with it or anything.
    
    This doesn't feel right.  Are you sure this is secure and won't
    break something else?
    
    Looking at the dpkg(8) man page I see mention of "hold"
       A package marked to be on hold is not handled by dpkg, unless
       forced to do that with option --force-hold.
    
    That sounds closer to what we should be using.  Basically it
    appears to be a hook in dpkg to lock up a package.  Have I
    interpreted its description correctly?
    -- 
    Allen Brown  abrown at peak.org  http://www.peak.org/~abrown/
       Which is it: is man one of God's blunders, or is God
       one of man's blunders? ---Friedrich Wilhelm Nietzsche
    
  • [Eug-lug] Linux- Mac OS X file exchange: This sounds right



    Allen BrownTue Aug 1 11:13:49 PDT 2006

    Bob Miller wrote:
    > Allen Brown wrote:
    > 
    > 
    >>It is tempting to also use nosuid, but there is a warning on
    >>the mount page.
    >>  nosuid Do  not allow set-user-identifier or set-group-identifier
    >>         bits to take effect. (This seems safe,  but  is  in  fact
    >>         rather unsafe if you have suidperl(1) installed.)
    >>
    >>What the heck is that?  I don't seem to have it installed,
    >>but this makes me nervous because I wouldn't necessarily
    >>notice if it came in along with a bunch of other stuff
    >>in an apt-get.
    > 
    > 
    > /usr/bin/suidperl part of the perl package.  It's a set-uid program,
    > usually installed setuid root, that invokes perl, used to change uid
    > on setuid scripts when the kernel doesn't do that.
    > 
    > An evildoer could...
    > 
    >    On his own box, create a floppy/CD/flash ext2 filesystem and put
    >    evilscript on it setuid root.
    > 
    >    On your box, with normal user privs, he inserts and mounts the
    >    device which you've marked with user,nosuid in /etc/fstab.
    > 
    >    The evildoer runs his script.  The kernel invokes perl but does not
    >    set uid (because the fs is mounted nosuid).  Perl sees the setuid
    >    bit, execs suidperl.  suidperl sees the setuid bit, changes its
    >    effective uid to the file's owner (root), and execs perl.  Perl,
    >    now running as root, executes the script, and hilarity ensues.
    > 
    > Many distros ship without suidperl.  Gentoo has a USE flag to enable
    > it which defaults to off.  Ubuntu ships with suidperl, but it doesn't
    > have the setuid bit set.  Those are the distros I have handy just now.
    > 
    > That's probably more information than you wanted...
    
    Not at all.  I'm glad to hear it.
    
    It does make me wonder why suidperl wasn't killed long ago.
    And it seems like the warning on the mount page is poorly
    worded since it implies that setting nosuid *opens* the hole
    exploited by suidperl.  What is more accurate is that suidperl
    *reopens* the hole that nosuid closed.
    
    So nosuid is a good thing.  But you also must forbid suidperl.
    -- 
    Allen Brown  abrown at peak.org  http://www.peak.org/~abrown/
       You can lead a horticulture but you can't make her think. ---Dorothy 
    Parker