• Find the path of a shell command

    From Paulo da Silva@21:1/5 to All on Wed Oct 12 05:00:08 2022
    Hi!

    The simple question: How do I find the full path of a shell command
    (linux), i.e. how do I obtain the corresponding of, for example,
    "type rm" in command line?

    The reason:
    I have python program that launches a detached rm. It works pretty well
    until it is invoked by cron! I suspect that for cron we need to specify
    the full path.
    Of course I can hardcode /usr/bin/rm. But, is rm always in /usr/bin?
    What about other commands?

    Thanks for any comments/responses.
    Paulo

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From jak@21:1/5 to All on Wed Oct 12 07:11:56 2022
    Il 12/10/2022 06:00, Paulo da Silva ha scritto:
    Hi!

    The simple question: How do I find the full path of a shell command
    (linux), i.e. how do I obtain the corresponding of, for example,
    "type rm" in command line?

    The reason:
    I have python program that launches a detached rm. It works pretty well
    until it is invoked by cron! I suspect that for cron we need to specify
    the full path.
    Of course I can hardcode /usr/bin/rm. But, is rm always in /usr/bin?
    What about other commands?

    Thanks for any comments/responses.
    Paulo


    I'm afraid you will have to look for the command in every path listed in
    the PATH environment variable.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From jkn@21:1/5 to jak on Wed Oct 12 00:40:38 2022
    On Wednesday, October 12, 2022 at 6:12:23 AM UTC+1, jak wrote:
    Il 12/10/2022 06:00, Paulo da Silva ha scritto:
    Hi!

    The simple question: How do I find the full path of a shell command (linux), i.e. how do I obtain the corresponding of, for example,
    "type rm" in command line?

    The reason:
    I have python program that launches a detached rm. It works pretty well until it is invoked by cron! I suspect that for cron we need to specify
    the full path.
    Of course I can hardcode /usr/bin/rm. But, is rm always in /usr/bin?
    What about other commands?

    Thanks for any comments/responses.
    Paulo

    I'm afraid you will have to look for the command in every path listed in
    the PATH environment variable.

    erm, or try 'which rm' ?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From jak@21:1/5 to All on Wed Oct 12 13:04:16 2022
    Il 12/10/2022 09:40, jkn ha scritto:
    On Wednesday, October 12, 2022 at 6:12:23 AM UTC+1, jak wrote:
    Il 12/10/2022 06:00, Paulo da Silva ha scritto:
    Hi!

    The simple question: How do I find the full path of a shell command
    (linux), i.e. how do I obtain the corresponding of, for example,
    "type rm" in command line?

    The reason:
    I have python program that launches a detached rm. It works pretty well
    until it is invoked by cron! I suspect that for cron we need to specify
    the full path.
    Of course I can hardcode /usr/bin/rm. But, is rm always in /usr/bin?
    What about other commands?

    Thanks for any comments/responses.
    Paulo

    I'm afraid you will have to look for the command in every path listed in
    the PATH environment variable.

    erm, or try 'which rm' ?

    You might but if you don't know where the 'rm' command is, you will have
    the same difficulty in using 'which' command. Do not you think?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From jak@21:1/5 to All on Wed Oct 12 13:07:47 2022
    Il 12/10/2022 09:40, jkn ha scritto:
    On Wednesday, October 12, 2022 at 6:12:23 AM UTC+1, jak wrote:
    Il 12/10/2022 06:00, Paulo da Silva ha scritto:
    Hi!

    The simple question: How do I find the full path of a shell command
    (linux), i.e. how do I obtain the corresponding of, for example,
    "type rm" in command line?

    The reason:
    I have python program that launches a detached rm. It works pretty well
    until it is invoked by cron! I suspect that for cron we need to specify
    the full path.
    Of course I can hardcode /usr/bin/rm. But, is rm always in /usr/bin?
    What about other commands?

    Thanks for any comments/responses.
    Paulo

    I'm afraid you will have to look for the command in every path listed in
    the PATH environment variable.

    erm, or try 'which rm' ?

    You might but if you don't know where the 'rm' command is, you will have
    the same difficulty in using 'which' command. Do not you think?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From jak@21:1/5 to All on Wed Oct 12 13:02:15 2022
    Il 12/10/2022 09:40, jkn ha scritto:
    On Wednesday, October 12, 2022 at 6:12:23 AM UTC+1, jak wrote:
    Il 12/10/2022 06:00, Paulo da Silva ha scritto:
    Hi!

    The simple question: How do I find the full path of a shell command
    (linux), i.e. how do I obtain the corresponding of, for example,
    "type rm" in command line?

    The reason:
    I have python program that launches a detached rm. It works pretty well
    until it is invoked by cron! I suspect that for cron we need to specify
    the full path.
    Of course I can hardcode /usr/bin/rm. But, is rm always in /usr/bin?
    What about other commands?

    Thanks for any comments/responses.
    Paulo

    I'm afraid you will have to look for the command in every path listed in
    the PATH environment variable.

    erm, or try 'which rm' ?

    You might but if you don't know where the 'rm' command is, you will have
    the same difficulty in using 'which' Command. Do not you think?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Stefan Ram@21:1/5 to Paulo da Silva on Wed Oct 12 11:38:10 2022
    Paulo da Silva <p_d_a_s_i_l_v_a_ns@nonetnoaddress.pt> writes:
    (linux), i.e. how do I obtain the corresponding of, for example,
    "type rm" in command line?

    import os
    import pathlib

    paths = os.getenv( "PATH" )
    for p in paths.split( os.pathsep ):
    path = pathlib.Path( p ).joinpath( 'rm' )
    try:
    if path.exists(): print( path )
    except PermissionError:
    pass

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From jak@21:1/5 to All on Wed Oct 12 13:29:06 2022
    Sorry for the repetitions. Today I have network problems.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Chris Green@21:1/5 to jak on Wed Oct 12 13:20:02 2022
    jak <nospam@please.ty> wrote:
    Il 12/10/2022 09:40, jkn ha scritto:
    On Wednesday, October 12, 2022 at 6:12:23 AM UTC+1, jak wrote:
    Il 12/10/2022 06:00, Paulo da Silva ha scritto:
    Hi!

    The simple question: How do I find the full path of a shell command
    (linux), i.e. how do I obtain the corresponding of, for example,
    "type rm" in command line?

    The reason:
    I have python program that launches a detached rm. It works pretty well >>> until it is invoked by cron! I suspect that for cron we need to specify >>> the full path.
    Of course I can hardcode /usr/bin/rm. But, is rm always in /usr/bin?
    What about other commands?

    Thanks for any comments/responses.
    Paulo

    I'm afraid you will have to look for the command in every path listed in >> the PATH environment variable.

    erm, or try 'which rm' ?

    You might but if you don't know where the 'rm' command is, you will have
    the same difficulty in using 'which' command. Do not you think?

    From a command prompt use the bash built-in 'command' :-

    command -v rm

    ... and rm will just about always be in /usr/bin.

    --
    Chris Green
    ·

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From jak@21:1/5 to All on Wed Oct 12 14:46:56 2022
    Il 12/10/2022 14:20, Chris Green ha scritto:
    jak <nospam@please.ty> wrote:
    Il 12/10/2022 09:40, jkn ha scritto:
    On Wednesday, October 12, 2022 at 6:12:23 AM UTC+1, jak wrote:
    Il 12/10/2022 06:00, Paulo da Silva ha scritto:
    Hi!

    The simple question: How do I find the full path of a shell command
    (linux), i.e. how do I obtain the corresponding of, for example,
    "type rm" in command line?

    The reason:
    I have python program that launches a detached rm. It works pretty well >>>>> until it is invoked by cron! I suspect that for cron we need to specify >>>>> the full path.
    Of course I can hardcode /usr/bin/rm. But, is rm always in /usr/bin? >>>>> What about other commands?

    Thanks for any comments/responses.
    Paulo

    I'm afraid you will have to look for the command in every path listed in >>>> the PATH environment variable.

    erm, or try 'which rm' ?

    You might but if you don't know where the 'rm' command is, you will have
    the same difficulty in using 'which' command. Do not you think?

    From a command prompt use the bash built-in 'command' :-

    command -v rm

    ... and rm will just about always be in /usr/bin.


    ok but I didn't suggest a very complicated thing:

    for p in os.getenv('PATH').split(os.path.pathsep):
    if p:
    if os.path.isfile(os.path.join(p, 'rm')):
    print(f)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Michael F. Stemper@21:1/5 to Chris Green on Wed Oct 12 09:38:49 2022
    On 12/10/2022 07.20, Chris Green wrote:
    jak <nospam@please.ty> wrote:
    Il 12/10/2022 09:40, jkn ha scritto:
    On Wednesday, October 12, 2022 at 6:12:23 AM UTC+1, jak wrote:

    I'm afraid you will have to look for the command in every path listed in >>>> the PATH environment variable.

    erm, or try 'which rm' ?

    You might but if you don't know where the 'rm' command is, you will have
    the same difficulty in using 'which' command. Do not you think?
    From a command prompt use the bash built-in 'command' :-

    command -v rm

    ... and rm will just about always be in /usr/bin.

    On two different versions of Ubuntu, it's in /bin.

    --
    Michael F. Stemper
    Psalm 94:3-6

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jon Ribbens@21:1/5 to Michael F. Stemper on Wed Oct 12 15:08:32 2022
    On 2022-10-12, Michael F. Stemper <michael.stemper@gmail.com> wrote:
    On 12/10/2022 07.20, Chris Green wrote:
    ... and rm will just about always be in /usr/bin.

    On two different versions of Ubuntu, it's in /bin.

    It will almost always be in /bin in any Unix or Unix-like system,
    because it's one of the fundamental utilities that may be vital in
    fixing the system when it's booted in single-user mode and /usr may
    not be available. Also, the Filesystem Hierarchy Standard *requires*
    it to be in /bin.

    Having said that, nothing requires it not to be elsewhere *as well*,
    and in Ubuntu and other Linux systems it is in /usr/bin too. And because
    PATH for non-root users will usually contain /usr/bin before /bin (or
    indeed may not contain /bin at all), 'command -v rm' or 'which rm' will
    usually list the version of rm that is in /usr/bin.

    e.g. on Amazon Linux:

    $ which rm
    /usr/bin/rm
    $ sudo which rm
    /bin/rm

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Chris Green@21:1/5 to Michael F. Stemper on Wed Oct 12 16:06:35 2022
    Michael F. Stemper <michael.stemper@gmail.com> wrote:
    On 12/10/2022 07.20, Chris Green wrote:
    jak <nospam@please.ty> wrote:
    Il 12/10/2022 09:40, jkn ha scritto:
    On Wednesday, October 12, 2022 at 6:12:23 AM UTC+1, jak wrote:

    I'm afraid you will have to look for the command in every path listed in >>>> the PATH environment variable.

    erm, or try 'which rm' ?

    You might but if you don't know where the 'rm' command is, you will have >> the same difficulty in using 'which' command. Do not you think?
    From a command prompt use the bash built-in 'command' :-

    command -v rm

    ... and rm will just about always be in /usr/bin.

    On two different versions of Ubuntu, it's in /bin.

    I think you'll find it's in both /bin and /usr/bin, usually /usr/bin
    is earlier in the path so /usr/bin/rm is the one that will normally be
    found first.

    It's only in /bin/rm in case one has a system which mounts /bin
    separately and earlier in the boot sequence and rm is one of the
    commands needed early on.

    --
    Chris Green
    ·

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Paulo da Silva@21:1/5 to All on Wed Oct 12 17:49:40 2022
    Às 05:00 de 12/10/22, Paulo da Silva escreveu:
    Hi!

    The simple question: How do I find the full path of a shell command
    (linux), i.e. how do I obtain the corresponding of, for example,
    "type rm" in command line?

    The reason:
    I have python program that launches a detached rm. It works pretty well
    until it is invoked by cron! I suspect that for cron we need to specify
    the full path.
    Of course I can hardcode /usr/bin/rm. But, is rm always in /usr/bin?
    What about other commands?

    Thank you all who have responded so far.
    I think that the the suggestion of searching the PATH env seems the best. Another thing that I thought of is that of the 'which', but, to avoid
    the mentioned recurrent problem of not knowing where 'which' is I would
    use 'type' instead. 'type' is a bash (sh?) command.

    Thanks
    Paulo

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Tilmann Hentze@21:1/5 to Paulo da Silva on Wed Oct 12 16:22:03 2022
    Paulo da Silva <p_d_a_s_i_l_v_a_ns@nonetnoaddress.pt> schrieb:
    I have python program that launches a detached rm. It works pretty well
    until it is invoked by cron! I suspect that for cron we need to specify
    the full path.

    Probably you could use os.unlink[1] with no problem.

    [1] <https://docs.python.org/3/library/os.html#os.unlink>

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Paulo da Silva@21:1/5 to All on Wed Oct 12 17:43:18 2022
    Às 17:22 de 12/10/22, Tilmann Hentze escreveu:
    Paulo da Silva <p_d_a_s_i_l_v_a_ns@nonetnoaddress.pt> schrieb:
    I have python program that launches a detached rm. It works pretty well
    until it is invoked by cron! I suspect that for cron we need to specify
    the full path.

    Probably you could use os.unlink[1] with no problem.
    No, because I need to launch several rm's that keep running after the
    script ends.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Joe Pfeiffer@21:1/5 to Jon Ribbens on Wed Oct 12 11:41:07 2022
    Jon Ribbens <jon+usenet@unequivocal.eu> writes:

    On 2022-10-12, Michael F. Stemper <michael.stemper@gmail.com> wrote:
    On 12/10/2022 07.20, Chris Green wrote:
    ... and rm will just about always be in /usr/bin.

    On two different versions of Ubuntu, it's in /bin.

    It will almost always be in /bin in any Unix or Unix-like system,
    because it's one of the fundamental utilities that may be vital in
    fixing the system when it's booted in single-user mode and /usr may
    not be available. Also, the Filesystem Hierarchy Standard *requires*
    it to be in /bin.

    Having said that, nothing requires it not to be elsewhere *as well*,
    and in Ubuntu and other Linux systems it is in /usr/bin too. And because
    PATH for non-root users will usually contain /usr/bin before /bin (or
    indeed may not contain /bin at all), 'command -v rm' or 'which rm' will usually list the version of rm that is in /usr/bin.

    e.g. on Amazon Linux:

    $ which rm
    /usr/bin/rm
    $ sudo which rm
    /bin/rm

    Have some major Linux distributions not done usrmerge yet? For any that
    have, /bin is a symbolic link to /usr/bin

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jon Ribbens@21:1/5 to Joe Pfeiffer on Wed Oct 12 18:08:18 2022
    On 2022-10-12, Joe Pfeiffer <pfeiffer@cs.nmsu.edu> wrote:
    Jon Ribbens <jon+usenet@unequivocal.eu> writes:

    On 2022-10-12, Michael F. Stemper <michael.stemper@gmail.com> wrote:
    On 12/10/2022 07.20, Chris Green wrote:
    ... and rm will just about always be in /usr/bin.

    On two different versions of Ubuntu, it's in /bin.

    It will almost always be in /bin in any Unix or Unix-like system,
    because it's one of the fundamental utilities that may be vital in
    fixing the system when it's booted in single-user mode and /usr may
    not be available. Also, the Filesystem Hierarchy Standard *requires*
    it to be in /bin.

    Having said that, nothing requires it not to be elsewhere *as well*,
    and in Ubuntu and other Linux systems it is in /usr/bin too. And because
    PATH for non-root users will usually contain /usr/bin before /bin (or
    indeed may not contain /bin at all), 'command -v rm' or 'which rm' will
    usually list the version of rm that is in /usr/bin.

    e.g. on Amazon Linux:

    $ which rm
    /usr/bin/rm
    $ sudo which rm
    /bin/rm

    Have some major Linux distributions not done usrmerge yet? For any that have, /bin is a symbolic link to /usr/bin

    I have immediate access to CentOS 7, Ubuntu 20, and Amazon Linux 2,
    and none of those have done that.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jon Ribbens@21:1/5 to Paulo da Silva on Wed Oct 12 18:14:40 2022
    On 2022-10-12, Paulo da Silva <p_d_a_s_i_l_v_a_ns@nonetnoaddress.pt> wrote:
    Às 05:00 de 12/10/22, Paulo da Silva escreveu:
    Hi!

    The simple question: How do I find the full path of a shell command
    (linux), i.e. how do I obtain the corresponding of, for example,
    "type rm" in command line?

    The reason:
    I have python program that launches a detached rm. It works pretty well
    until it is invoked by cron! I suspect that for cron we need to specify
    the full path.
    Of course I can hardcode /usr/bin/rm. But, is rm always in /usr/bin?
    What about other commands?

    Thank you all who have responded so far.
    I think that the the suggestion of searching the PATH env seems the best. Another thing that I thought of is that of the 'which', but, to avoid
    the mentioned recurrent problem of not knowing where 'which' is I would
    use 'type' instead. 'type' is a bash (sh?) command.

    If you're using subprocess.run / subprocess.Popen then the computer is *already* searching PATH for you. Your problem must be that your cron
    job is being run without PATH being set, perhaps you just need to edit
    your crontab to set PATH to something sensible. Or just hard-code your
    program to run '/bin/rm' explicitly, which should always work (unless
    you're on Windows, of course!)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From jkn@21:1/5 to jak on Wed Oct 12 11:33:35 2022
    On Wednesday, October 12, 2022 at 12:07:36 PM UTC+1, jak wrote:
    Il 12/10/2022 09:40, jkn ha scritto:
    On Wednesday, October 12, 2022 at 6:12:23 AM UTC+1, jak wrote:
    Il 12/10/2022 06:00, Paulo da Silva ha scritto:
    Hi!

    The simple question: How do I find the full path of a shell command
    (linux), i.e. how do I obtain the corresponding of, for example,
    "type rm" in command line?

    The reason:
    I have python program that launches a detached rm. It works pretty well >>> until it is invoked by cron! I suspect that for cron we need to specify >>> the full path.
    Of course I can hardcode /usr/bin/rm. But, is rm always in /usr/bin?
    What about other commands?

    Thanks for any comments/responses.
    Paulo

    I'm afraid you will have to look for the command in every path listed in >> the PATH environment variable.

    erm, or try 'which rm' ?
    You might but if you don't know where the 'rm' command is, you will have
    the same difficulty in using 'which' Command. Do not you think?

    I don't need to know where the rm command is in order to use the which command.

    I *was* (knowingly and deliberately) assuming that you have a semi-reasonably working system, and that your question meant "given command X, how do I
    find where the executable X is on my system?".

    Sounds like you want to make less assumptions than that. Fine. but probably best to be clear about your assumptions up front.

    J^n

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From MRAB@21:1/5 to jak on Wed Oct 12 19:19:42 2022
    On 2022-10-12 06:11, jak wrote:
    Il 12/10/2022 06:00, Paulo da Silva ha scritto:
    Hi!

    The simple question: How do I find the full path of a shell command
    (linux), i.e. how do I obtain the corresponding of, for example,
    "type rm" in command line?

    The reason:
    I have python program that launches a detached rm. It works pretty well
    until it is invoked by cron! I suspect that for cron we need to specify
    the full path.
    Of course I can hardcode /usr/bin/rm. But, is rm always in /usr/bin?
    What about other commands?

    Thanks for any comments/responses.
    Paulo


    I'm afraid you will have to look for the command in every path listed in
    the PATH environment variable.

    Isn't that what the "whereis" command does?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Antoon Pardon@21:1/5 to All on Wed Oct 12 21:09:58 2022
    Op 12/10/2022 om 18:49 schreef Paulo da Silva:
    Às 05:00 de 12/10/22, Paulo da Silva escreveu:
    Hi!

    The simple question: How do I find the full path of a shell command
    (linux), i.e. how do I obtain the corresponding of, for example,
    "type rm" in command line?

    The reason:
    I have python program that launches a detached rm. It works pretty
    well until it is invoked by cron! I suspect that for cron we need to
    specify the full path.
    Of course I can hardcode /usr/bin/rm. But, is rm always in /usr/bin?
    What about other commands?

    Thank you all who have responded so far.
    I think that the the suggestion of searching the PATH env seems the best.

    I fear that won't work.

    If it doesn't work in cron, that probably means, PATH is not set
    properly in your cron environment. And if PATH is not set properly,
    searching it explicitely won't work either.

    If rm works when evoked directly in a cron script but not via a python
    script, you may need to export the PATH in your cron script.

    --
    Antoon Pardon

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From 2QdxY4RzWzUUiLuE@potatochowder.com@21:1/5 to Paulo da Silva on Wed Oct 12 15:16:02 2022
    On 2022-10-12 at 17:43:18 +0100,
    Paulo da Silva <p_d_a_s_i_l_v_a_ns@nonetnoaddress.pt> wrote:

    Às 17:22 de 12/10/22, Tilmann Hentze escreveu:
    Paulo da Silva <p_d_a_s_i_l_v_a_ns@nonetnoaddress.pt> schrieb:
    I have python program that launches a detached rm. It works pretty well until it is invoked by cron! I suspect that for cron we need to specify the full path.

    Probably you could use os.unlink[1] with no problem.
    No, because I need to launch several rm's that keep running after the script ends.

    rm doesn't take that long. Why are you detaching them?

    (I'm not debating your point about cron.)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Paulo da Silva@21:1/5 to All on Wed Oct 12 21:45:54 2022
    Às 20:16 de 12/10/22, 2QdxY4RzWzUUiLuE@potatochowder.com escreveu:
    On 2022-10-12 at 17:43:18 +0100,
    Paulo da Silva <p_d_a_s_i_l_v_a_ns@nonetnoaddress.pt> wrote:

    Às 17:22 de 12/10/22, Tilmann Hentze escreveu:
    Paulo da Silva <p_d_a_s_i_l_v_a_ns@nonetnoaddress.pt> schrieb:
    I have python program that launches a detached rm. It works pretty well >>>> until it is invoked by cron! I suspect that for cron we need to specify >>>> the full path.

    Probably you could use os.unlink[1] with no problem.
    No, because I need to launch several rm's that keep running after the script >> ends.

    rm doesn't take that long. Why are you detaching them?

    Because the use of "rm -rf" here is to remove full dirs, mostly in
    external drives, each reaching more than hundreds thousand files.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Paulo da Silva@21:1/5 to All on Wed Oct 12 21:51:39 2022
    Às 19:14 de 12/10/22, Jon Ribbens escreveu:
    On 2022-10-12, Paulo da Silva <p_d_a_s_i_l_v_a_ns@nonetnoaddress.pt> wrote:
    Às 05:00 de 12/10/22, Paulo da Silva escreveu:
    Hi!

    The simple question: How do I find the full path of a shell command
    (linux), i.e. how do I obtain the corresponding of, for example,
    "type rm" in command line?

    The reason:
    I have python program that launches a detached rm. It works pretty well
    until it is invoked by cron! I suspect that for cron we need to specify
    the full path.
    Of course I can hardcode /usr/bin/rm. But, is rm always in /usr/bin?
    What about other commands?

    Thank you all who have responded so far.
    I think that the the suggestion of searching the PATH env seems the best.
    Another thing that I thought of is that of the 'which', but, to avoid
    the mentioned recurrent problem of not knowing where 'which' is I would
    use 'type' instead. 'type' is a bash (sh?) command.

    If you're using subprocess.run / subprocess.Popen then the computer is *already* searching PATH for you.
    Yes, and it works out of cron.
    Your problem must be that your cron
    job is being run without PATH being set, perhaps you just need to edit
    your crontab to set PATH to something sensible.
    I could do that, but I am using /etc/cron.* for convenience.

    Or just hard-code your
    program to run '/bin/rm' explicitly, which should always work (unless
    you're on Windows, of course!)
    It can also be in /bin, at least.
    A short idea is to just check /bin/rm and /usr/bin/rm, but I prefer
    searching thru PATH env. It only needs to do that once.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jon Ribbens@21:1/5 to Jon Ribbens on Wed Oct 12 20:54:19 2022
    On 2022-10-12, Jon Ribbens <jon+usenet@unequivocal.eu> wrote:
    On 2022-10-12, Joe Pfeiffer <pfeiffer@cs.nmsu.edu> wrote:
    Jon Ribbens <jon+usenet@unequivocal.eu> writes:

    On 2022-10-12, Michael F. Stemper <michael.stemper@gmail.com> wrote:
    On 12/10/2022 07.20, Chris Green wrote:
    ... and rm will just about always be in /usr/bin.

    On two different versions of Ubuntu, it's in /bin.

    It will almost always be in /bin in any Unix or Unix-like system,
    because it's one of the fundamental utilities that may be vital in
    fixing the system when it's booted in single-user mode and /usr may
    not be available. Also, the Filesystem Hierarchy Standard *requires*
    it to be in /bin.

    Having said that, nothing requires it not to be elsewhere *as well*,
    and in Ubuntu and other Linux systems it is in /usr/bin too. And because >>> PATH for non-root users will usually contain /usr/bin before /bin (or
    indeed may not contain /bin at all), 'command -v rm' or 'which rm' will
    usually list the version of rm that is in /usr/bin.

    e.g. on Amazon Linux:

    $ which rm
    /usr/bin/rm
    $ sudo which rm
    /bin/rm

    Have some major Linux distributions not done usrmerge yet? For any that
    have, /bin is a symbolic link to /usr/bin

    I have immediate access to CentOS 7, Ubuntu 20, and Amazon Linux 2,
    and none of those have done that.

    Sorry, in fact they have done that - I misread your comment as being
    that they had symlinked the executables not the directories. This seems
    quite an unwise move to me but presumably they've thought it through.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Paulo da Silva@21:1/5 to All on Wed Oct 12 21:56:16 2022
    Às 20:09 de 12/10/22, Antoon Pardon escreveu:


    Op 12/10/2022 om 18:49 schreef Paulo da Silva:
    Às 05:00 de 12/10/22, Paulo da Silva escreveu:
    Hi!

    The simple question: How do I find the full path of a shell command
    (linux), i.e. how do I obtain the corresponding of, for example,
    "type rm" in command line?

    The reason:
    I have python program that launches a detached rm. It works pretty
    well until it is invoked by cron! I suspect that for cron we need to
    specify the full path.
    Of course I can hardcode /usr/bin/rm. But, is rm always in /usr/bin?
    What about other commands?

    Thank you all who have responded so far.
    I think that the the suggestion of searching the PATH env seems the best.

    I fear that won't work.

    If it doesn't work in cron, that probably means, PATH is not set
    properly in your cron environment. And if PATH is not set properly,
    searching it explicitely won't work either.

    It seems you are right :-( I didn't think of that!
    Does 'type' bash command work? I don't know how bash 'type' works.
    I need to do some tests.
    Thanks
    Paulo

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Grant Edwards@21:1/5 to 2QdxY4RzWzUUiLuE@potatochowder.com on Wed Oct 12 14:02:04 2022
    On 2022-10-12, 2QdxY4RzWzUUiLuE@potatochowder.com <2QdxY4RzWzUUiLuE@potatochowder.com> wrote:
    On 2022-10-12 at 17:43:18 +0100, Paulo da Silva <p_d_a_s_i_l_v_a_ns@nonetnoaddress.pt> wrote:

    Probably you could use os.unlink[1] with no problem.

    No, because I need to launch several rm's that keep running after the script >> ends.

    rm doesn't take that long.

    Recursive ones can take a long time.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From jak@21:1/5 to All on Wed Oct 12 23:14:46 2022
    Il 12/10/2022 20:19, MRAB ha scritto:
    On 2022-10-12 06:11, jak wrote:
    Il 12/10/2022 06:00, Paulo da Silva ha scritto:
    Hi!

    The simple question: How do I find the full path of a shell command
    (linux), i.e. how do I obtain the corresponding of, for example,
    "type rm" in command line?

    The reason:
    I have python program that launches a detached rm. It works pretty
    well until it is invoked by cron! I suspect that for cron we need to
    specify the full path.
    Of course I can hardcode /usr/bin/rm. But, is rm always in /usr/bin?
    What about other commands?

    Thanks for any comments/responses.
    Paulo


    I'm afraid you will have to look for the command in every path listed in
    the PATH environment variable.

    Isn't that what the "whereis" command does?

    "whereis" does more than the OP wants. A suitable command could be
    "which" but if the OP is in a context where he needs to know the path
    of the command, then it will have the same problem with "whereis" or
    "which". In any case they would be a few lines of Python:

    import os

    def which(c):
    for p in os.getenv('PATH').split(os.path.pathsep):
    if p and os.path.isfile(f := os.path.join(p, c)):
    return f
    return ''

    cmd = 'explorer.exe'
    cmdp = which(cmd)

    if cmdp:
    print("found:", cmdp)
    else:
    print("not found"

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jon Ribbens@21:1/5 to Paulo da Silva on Wed Oct 12 21:17:29 2022
    On 2022-10-12, Paulo da Silva <p_d_a_s_i_l_v_a_ns@nonetnoaddress.pt> wrote:
    Às 19:14 de 12/10/22, Jon Ribbens escreveu:
    On 2022-10-12, Paulo da Silva <p_d_a_s_i_l_v_a_ns@nonetnoaddress.pt> wrote: >>> Às 05:00 de 12/10/22, Paulo da Silva escreveu:
    Hi!

    The simple question: How do I find the full path of a shell command
    (linux), i.e. how do I obtain the corresponding of, for example,
    "type rm" in command line?

    The reason:
    I have python program that launches a detached rm. It works pretty well >>>> until it is invoked by cron! I suspect that for cron we need to specify >>>> the full path.
    Of course I can hardcode /usr/bin/rm. But, is rm always in /usr/bin?
    What about other commands?

    Thank you all who have responded so far.
    I think that the the suggestion of searching the PATH env seems the best. >>> Another thing that I thought of is that of the 'which', but, to avoid
    the mentioned recurrent problem of not knowing where 'which' is I would
    use 'type' instead. 'type' is a bash (sh?) command.

    If you're using subprocess.run / subprocess.Popen then the computer is
    *already* searching PATH for you.
    Yes, and it works out of cron.
    Your problem must be that your cron
    job is being run without PATH being set, perhaps you just need to edit
    your crontab to set PATH to something sensible.
    I could do that, but I am using /etc/cron.* for convenience.

    Or just hard-code your
    program to run '/bin/rm' explicitly, which should always work (unless
    you're on Windows, of course!)
    It can also be in /bin, at least.

    I assume you mean /usr/bin. But it doesn't matter. As already
    discussed, even if 'rm' is in /usr/bin, it will be in /bin as well
    (or /usr/bin and /bin will be symlinks to the same place).

    A short idea is to just check /bin/rm and /usr/bin/rm, but I prefer
    searching thru PATH env. It only needs to do that once.

    I cannot think of any situation in which that will help you. But if for
    some reason you really want to do that, you can use the shutil.which()
    function from the standard library:

    >>> import shutil
    >>> shutil.which('rm')
    '/usr/bin/rm'

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Weatherby,Gerard@21:1/5 to 2QdxY4RzWzUUiLuE@potatochowder.com on Wed Oct 12 21:25:54 2022
    Some thoughts / notes:
    1. On our Ubuntu-Server 20.04.3 based systems, /bin/rm and /usr/bin/rm are hard links to the same file.

    2. Put the following in a bash script and run it from cron. Then you can see what your environment is. Mine has PATH=/usr/bin:/bin in it.

    #!/bin/bash
    env > /tmp/env$$

    3. You can background Python just as well as you can a separate rm invocation. if os.fork() == 0:
    os.unlink(….)








    From: Python-list <python-list-bounces+gweatherby=uchc.edu@python.org> on behalf of Grant Edwards <grant.b.edwards@gmail.com>
    Date: Wednesday, October 12, 2022 at 5:03 PM
    To: python-list@python.org <python-list@python.org>
    Subject: Re: Find the path of a shell command
    *** Attention: This is an external email. Use caution responding, opening attachments or clicking on links. ***

    On 2022-10-12, 2QdxY4RzWzUUiLuE@potatochowder.com <2QdxY4RzWzUUiLuE@potatochowder.com> wrote:
    On 2022-10-12 at 17:43:18 +0100, Paulo da Silva <p_d_a_s_i_l_v_a_ns@nonetnoaddress.pt> wrote:

    Probably you could use os.unlink[1] with no problem.

    No, because I need to launch several rm's that keep running after the script >> ends.

    rm doesn't take that long.

    Recursive ones can take a long time.

    -- https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!ny8-fSGJEE3wk-Yq188xuT5aamgIUVI6SJQHkNaxMp11JelflHEJ2SQcYqqSC1s8pxkifVVdFyeEcbSv1ZJlqoaxuG_m$<https://urldefense.com/v3/__https:/mail.python.org/mailman/
    listinfo/python-list__;!!Cn_UX_p3!ny8-fSGJEE3wk-Yq188xuT5aamgIUVI6SJQHkNaxMp11JelflHEJ2SQcYqqSC1s8pxkifVVdFyeEcbSv1ZJlqoaxuG_m$>

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jon Ribbens@21:1/5 to Jon Ribbens on Wed Oct 12 21:38:27 2022
    On 2022-10-12, Jon Ribbens <jon+usenet@unequivocal.eu> wrote:
    On 2022-10-12, Paulo da Silva <p_d_a_s_i_l_v_a_ns@nonetnoaddress.pt> wrote:
    Às 19:14 de 12/10/22, Jon Ribbens escreveu:
    On 2022-10-12, Paulo da Silva <p_d_a_s_i_l_v_a_ns@nonetnoaddress.pt> wrote: >>>> Às 05:00 de 12/10/22, Paulo da Silva escreveu:
    Hi!

    The simple question: How do I find the full path of a shell command
    (linux), i.e. how do I obtain the corresponding of, for example,
    "type rm" in command line?

    The reason:
    I have python program that launches a detached rm. It works pretty well >>>>> until it is invoked by cron! I suspect that for cron we need to specify >>>>> the full path.
    Of course I can hardcode /usr/bin/rm. But, is rm always in /usr/bin? >>>>> What about other commands?

    Thank you all who have responded so far.
    I think that the the suggestion of searching the PATH env seems the best. >>>> Another thing that I thought of is that of the 'which', but, to avoid
    the mentioned recurrent problem of not knowing where 'which' is I would >>>> use 'type' instead. 'type' is a bash (sh?) command.

    If you're using subprocess.run / subprocess.Popen then the computer is
    *already* searching PATH for you.
    Yes, and it works out of cron.
    Your problem must be that your cron
    job is being run without PATH being set, perhaps you just need to edit
    your crontab to set PATH to something sensible.
    I could do that, but I am using /etc/cron.* for convenience.

    Or just hard-code your
    program to run '/bin/rm' explicitly, which should always work (unless
    you're on Windows, of course!)
    It can also be in /bin, at least.

    I assume you mean /usr/bin. But it doesn't matter. As already
    discussed, even if 'rm' is in /usr/bin, it will be in /bin as well
    (or /usr/bin and /bin will be symlinks to the same place).

    A short idea is to just check /bin/rm and /usr/bin/rm, but I prefer
    searching thru PATH env. It only needs to do that once.

    I cannot think of any situation in which that will help you. But if for
    some reason you really want to do that, you can use the shutil.which() function from the standard library:

    >>> import shutil
    >>> shutil.which('rm')
    '/usr/bin/rm'

    Actually if I'm mentioning shutil I should probably mention
    shutil.rmtree() as well, which does the same as 'rm -r', without
    needing to find or run any other executables.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Thomas Passin@21:1/5 to Paulo da Silva on Wed Oct 12 17:28:17 2022
    On 10/12/2022 12:00 AM, Paulo da Silva wrote:
    Hi!

    The simple question: How do I find the full path of a shell command
    (linux), i.e. how do I obtain the corresponding of, for example,
    "type rm" in command line?

    The reason:
    I have python program that launches a detached rm. It works pretty well
    until it is invoked by cron! I suspect that for cron we need to specify
    the full path.
    Of course I can hardcode /usr/bin/rm. But, is rm always in /usr/bin?
    What about other commands?

    Thanks for any comments/responses.
    Paulo


    Python has a command that usually does the job:

    import shutil, os
    executable_path = shutil.which(exename, os.X_OK)

    If you know that the executable you want is on some non-standard path,
    you can or them together:

    executable_path = shutil.which(exename, os.X_OK)\
    or shutil.which(exename, os.X_OK, other_path)

    Presumably the shutil command uses which behind the scenes, but that
    doesn't matter.

    Now you can include this location when you run the executable from
    Python. If you need to run a system command from a batch file and not
    from Python, you will either need to have the right path in effect when
    the batch file is run, or manually include the full path to the file in
    the batch file.

    BTW, on Linux Mint, which is derived from Ubuntu and Debian, rm is at

    $ which rm
    /bin/rm

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Cameron Simpson@21:1/5 to Paulo da Silva on Thu Oct 13 08:43:18 2022
    On 12Oct2022 17:49, Paulo da Silva <p_d_a_s_i_l_v_a_ns@nonetnoaddress.pt> wrote:
    Às 05:00 de 12/10/22, Paulo da Silva escreveu:
    I think that the the suggestion of searching the PATH env seems the
    best.

    I just want to note that you want to not just check for existence of the
    path, but that it is executable (permissionwise). You want to use `X_OK`
    with the `os.access` function: https://docs.python.org/3/library/os.html#os.access

    Also notice that the `shutil` module has a `which()` function: https://docs.python.org/3/library/shutil.html#shutil.which

    Another thing that I thought of is that of the 'which', but, to avoid
    the mentioned recurrent problem of not knowing where 'which' is I
    would use 'type' instead.

    `which` will almost always be in `/usr/bin` (or `/bin` on some systems I suppose). But do you need to know where `which` is? If you're invoking
    it instead of search `$PATH`, the normal executtion stuff itself search `$PATH`, an will find `which` for you :-)

    'type' is a bash (sh?) command.

    Yeah. Bash, ksh etc have `type`. It is a builtin, shich can see if a
    command word you give it is a shell alias or function or builtin or
    externally executed command. As you'd imagine, an external executable
    like `which` has no access to the internals of your shell, and can only
    look for executables.

    Cheers,
    Cameron Simpson <cs@cskk.id.au>

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Cameron Simpson@21:1/5 to Dan Sommers on Thu Oct 13 08:50:13 2022
    On 12Oct2022 15:16, Dan Sommers <2QdxY4RzWzUUiLuE@potatochowder.com> wrote:
    rm doesn't take that long. Why are you detaching them?

    For big things it takes quite a while. On slow discs it can take quite a
    while. For directory trees with many files it can take quite a while.
    For remove filesystems, even a local to your LAN NAS, it can take quite
    a while.

    Certainly I've got real world modern day things right now where "quite a
    while" can be many minutes.

    I've got an `rmr` script of my own whose entire function is to rename
    the target to something like `.frm.blah` and then remove `.frm.blah` in
    the background. I use it a _lot_.

    Ancient anecdote. We got funky new workstations at Uni long ago. For the
    first time in my life "rm filename" came back to the command prompt with
    no perceptable delay. So fast that I first wondered if it had worked at
    all. Previously we'd been using shared minicomputers (PDPs, Vaxen).

    Cheers,
    Cameron Simpson <cs@cskk.id.au>

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Paulo da Silva@21:1/5 to All on Wed Oct 12 23:59:32 2022
    Às 22:38 de 12/10/22, Jon Ribbens escreveu:
    On 2022-10-12, Jon Ribbens <jon+usenet@unequivocal.eu> wrote:
    On 2022-10-12, Paulo da Silva <p_d_a_s_i_l_v_a_ns@nonetnoaddress.pt> wrote: >>> Às 19:14 de 12/10/22, Jon Ribbens escreveu:
    On 2022-10-12, Paulo da Silva <p_d_a_s_i_l_v_a_ns@nonetnoaddress.pt> wrote:
    Às 05:00 de 12/10/22, Paulo da Silva escreveu:
    Hi!

    The simple question: How do I find the full path of a shell command >>>>>> (linux), i.e. how do I obtain the corresponding of, for example,
    "type rm" in command line?

    The reason:
    I have python program that launches a detached rm. It works pretty well >>>>>> until it is invoked by cron! I suspect that for cron we need to specify >>>>>> the full path.
    Of course I can hardcode /usr/bin/rm. But, is rm always in /usr/bin? >>>>>> What about other commands?

    Thank you all who have responded so far.
    I think that the the suggestion of searching the PATH env seems the best. >>>>> Another thing that I thought of is that of the 'which', but, to avoid >>>>> the mentioned recurrent problem of not knowing where 'which' is I would >>>>> use 'type' instead. 'type' is a bash (sh?) command.

    If you're using subprocess.run / subprocess.Popen then the computer is >>>> *already* searching PATH for you.
    Yes, and it works out of cron.
    Your problem must be that your cron
    job is being run without PATH being set, perhaps you just need to edit >>>> your crontab to set PATH to something sensible.
    I could do that, but I am using /etc/cron.* for convenience.

    Or just hard-code your
    program to run '/bin/rm' explicitly, which should always work (unless
    you're on Windows, of course!)
    It can also be in /bin, at least.

    I assume you mean /usr/bin. But it doesn't matter. As already
    discussed, even if 'rm' is in /usr/bin, it will be in /bin as well
    (or /usr/bin and /bin will be symlinks to the same place).

    A short idea is to just check /bin/rm and /usr/bin/rm, but I prefer
    searching thru PATH env. It only needs to do that once.

    I cannot think of any situation in which that will help you. But if for
    some reason you really want to do that, you can use the shutil.which()
    function from the standard library:

    >>> import shutil
    >>> shutil.which('rm')
    '/usr/bin/rm'

    Actually if I'm mentioning shutil I should probably mention
    shutil.rmtree() as well, which does the same as 'rm -r', without
    needing to find or run any other executables.
    Except that you can't have parallel tasks, at least in an easy way.
    Using Popen I just launch rm's and end the script.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Cameron Simpson@21:1/5 to Cameron Simpson on Thu Oct 13 09:47:01 2022
    On 13Oct2022 08:50, Cameron Simpson <cs@cskk.id.au> wrote:
    On 12Oct2022 15:16, Dan Sommers <2QdxY4RzWzUUiLuE@potatochowder.com> wrote: >>rm doesn't take that long. Why are you detaching them?

    [...]
    For remove filesystems, even a local to your LAN NAS, it can take quite
    a while.

    Of course I meant "remote" here, not "remove".

    Cheers,
    Cameron Simpson <cs@cskk.id.au>

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Cameron Simpson@21:1/5 to Jon Ribbens on Thu Oct 13 09:50:26 2022
    On 12Oct2022 20:54, Jon Ribbens <jon+usenet@unequivocal.eu> wrote:
    On 2022-10-12, Jon Ribbens <jon+usenet@unequivocal.eu> wrote:
    On 2022-10-12, Joe Pfeiffer <pfeiffer@cs.nmsu.edu> wrote:
    Jon Ribbens <jon+usenet@unequivocal.eu> writes:
    on Amazon Linux:

    $ which rm
    /usr/bin/rm
    $ sudo which rm
    /bin/rm

    Have some major Linux distributions not done usrmerge yet? For any that >>> have, /bin is a symbolic link to /usr/bin

    The above example may just be a different ordering in $PATH.

    I have immediate access to CentOS 7, Ubuntu 20, and Amazon Linux 2,
    and none of those have done that.

    Sorry, in fact they have done that - I misread your comment as being
    that they had symlinked the executables not the directories. This seems
    quite an unwise move to me but presumably they've thought it through.

    I think that modern discs are so large these days that the scenario of
    having a small critical /bin with a larger less critical /usr/bin on
    another partition are behind us except in very niche circumstances.

    Cheers,
    Cameron Simpson <cs@cskk.id.au>

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Peter J. Holzer@21:1/5 to Paulo da Silva on Thu Oct 13 01:40:29 2022
    On 2022-10-12 21:51:39 +0100, Paulo da Silva wrote:
    Às 19:14 de 12/10/22, Jon Ribbens escreveu:
    If you're using subprocess.run / subprocess.Popen then the computer is *already* searching PATH for you.
    Yes, and it works out of cron.
    Your problem must be that your cron
    job is being run without PATH being set, perhaps you just need to edit
    your crontab to set PATH to something sensible.

    The PATH in cron includes the directories with standard commands like
    "rm" by default. If a cron job doesn't find rm, either
    * rm isn't where it is supposed to be, or
    * PATH has been changed.

    I could do that, but I am using /etc/cron.* for convenience.

    That may be a clue. Does any of the /etc/cron.* files set PATH to weird
    value?

    In any case I find that when debugging such problems it is helpful to
    find out what the actual environment is. A simple

    * * * * * nobody echo $PATH >> /tmp/path.$$

    should do that.

    hp

    --
    _ | Peter J. Holzer | Story must make more sense than reality.
    |_|_) | |
    | | | hjp@hjp.at | -- Charles Stross, "Creative writing
    __/ | http://www.hjp.at/ | challenge!"

    -----BEGIN PGP SIGNATURE-----

    iQIzBAABCgAdFiEETtJbRjyPwVTYGJ5k8g5IURL+KF0FAmNHUGgACgkQ8g5IURL+ KF1M1w/+L96WRYdA+GSuI5xF5LbuaxAP6kMScVUpwfWC4+cBZKoMv1JbOUw14I9v WrxTpF750BoiR8HqtWA3kiJE6/2Sruo+Mk6qCvaHUDwcS2a4KCvlbD2znbCnz9nY totis16LAqG/Amsw3uZsI/mA5vbdm5sfuWkRBr/zY8mLHtsCZCQ085DdFd1TaS6x 5TvLiaqB0uzGDTbjVatY2Oly1Miwb+s6fNmo/iO4d048CNTsdKluX1qvKACvdehK ABgSy/2wcUlNqkV29jG7VPSlKkWmNR6qssqPbhtGBf0Ov0yNy4aPvTNM9Kqpl9zl QfdYVFNLAYHuBehAgxc3beAeFcNnbggozrTU0r+yuFuTzxfLdqlc0XyRpWPaQjAt p14cz49sGUPcGupca486Y5h2in7yAGivTnoKYe4q+0zGoKe1VFViwqpFdZEDsOCP sHCQLA8BiN06Uw/+VxCMlU8QRrT9f8DRPulYdlynkVh97rpBxM8CY2c5wNFPHUgd etk9hO/eNQ7uhKkVwvnCo1RUmNFB4O9kGKc0pt/wwKwzpCJ7nlmrj3jjpeW8dCjj J8hB7t1pidX7JHPaWO4j/QljZ7AgwYCNWI9SJEJzKuJxqe8JLpWp6QxSuQg2ppxE l3kTKq88W+Wrk6/QTAWfpKfpcmHJvPjP1TWHaV/
  • From Joe Pfeiffer@21:1/5 to Cameron Simpson on Wed Oct 12 17:58:48 2022
    Cameron Simpson <cs@cskk.id.au> writes:

    On 12Oct2022 20:54, Jon Ribbens <jon+usenet@unequivocal.eu> wrote:
    On 2022-10-12, Jon Ribbens <jon+usenet@unequivocal.eu> wrote:
    On 2022-10-12, Joe Pfeiffer <pfeiffer@cs.nmsu.edu> wrote:
    Jon Ribbens <jon+usenet@unequivocal.eu> writes:
    on Amazon Linux:

    $ which rm
    /usr/bin/rm
    $ sudo which rm
    /bin/rm

    Have some major Linux distributions not done usrmerge yet? For any that >>>> have, /bin is a symbolic link to /usr/bin

    The above example may just be a different ordering in $PATH.

    Sure, but the point is OP can use either /bin/rm or /usr/bin/rm on the
    vast majority of systems and execute the same command.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From rbowman@21:1/5 to Chris Green on Wed Oct 12 20:08:24 2022
    On 10/12/22 09:06, Chris Green wrote:
    Michael F. Stemper <michael.stemper@gmail.com> wrote:
    On 12/10/2022 07.20, Chris Green wrote:
    jak <nospam@please.ty> wrote:
    Il 12/10/2022 09:40, jkn ha scritto:
    On Wednesday, October 12, 2022 at 6:12:23 AM UTC+1, jak wrote:

    I'm afraid you will have to look for the command in every path listed in >>>>>> the PATH environment variable.

    erm, or try 'which rm' ?

    You might but if you don't know where the 'rm' command is, you will have >>>> the same difficulty in using 'which' command. Do not you think?
    From a command prompt use the bash built-in 'command' :-

    command -v rm

    ... and rm will just about always be in /usr/bin.

    On two different versions of Ubuntu, it's in /bin.

    I think you'll find it's in both /bin and /usr/bin, usually /usr/bin
    is earlier in the path so /usr/bin/rm is the one that will normally be
    found first.

    It's only in /bin/rm in case one has a system which mounts /bin
    separately and earlier in the boot sequence and rm is one of the
    commands needed early on.


    ls -l /bin
    lrwxrwxrwx 1 root root 7 Sep 23 01:41 /bin -> usr/bin

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Paulo da Silva@21:1/5 to All on Thu Oct 13 03:25:51 2022
    Às 05:00 de 12/10/22, Paulo da Silva escreveu:
    Hi!

    The simple question: How do I find the full path of a shell command
    (linux), i.e. how do I obtain the corresponding of, for example,
    "type rm" in command line?

    The reason:
    I have python program that launches a detached rm. It works pretty well
    until it is invoked by cron! I suspect that for cron we need to specify
    the full path.
    Of course I can hardcode /usr/bin/rm. But, is rm always in /usr/bin?
    What about other commands?

    For now I will postpone this problem.
    I just wrote a small script to delete a dir using rm and it works even
    under cron!
    There is another problem involved. The script, works fine except when
    launched by cron! Why?
    I'll have to look into this later when I have more time.
    For now I solved the problem using a complementary shell script.

    Thank you very much to those who responded.
    Paulo

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Cameron Simpson@21:1/5 to Paulo da Silva on Thu Oct 13 15:56:32 2022
    On 13Oct2022 03:25, Paulo da Silva <p_d_a_s_i_l_v_a_ns@nonetnoaddress.pt> wrote:
    There is another problem involved. The script, works fine except when >launched by cron! Why?

    Record the script output:

    # record all output
    exec >/tmp/script.$$.out 2>&1
    # dump the envionment
    env | sort
    # turn on execution tracing
    set -x
    ... rest of the script

    and have a look afterwards. Cron's environment is very minimal. This
    will show you what's in it.

    Cheers,
    Cameron Simpson <cs@cskk.id.au>

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Eli the Bearded@21:1/5 to jkn_gg@nicorp.f9.co.uk on Thu Oct 13 04:46:05 2022
    In comp.lang.python, jkn <jkn_gg@nicorp.f9.co.uk> wrote:
    On Wednesday, October 12, 2022 at 6:12:23 AM UTC+1, jak wrote:
    I'm afraid you will have to look for the command in every path listed in
    the PATH environment variable.
    erm, or try 'which rm' ?

    It is so hilarious seeing the responses to this thread. Hint: what do
    you think the `which` program does?

    $ touch /var/tmp/rm
    $ chmod 755 /var/tmp/rm
    $ env -i PATH=/etc:/usr:/lib:/var/tmp:/tmp /usr/bin/which rm
    /var/tmp/rm
    $ mv /var/tmp/rm /tmp/
    $ env -i PATH=/etc:/usr:/lib:/var/tmp:/tmp /usr/bin/which rm
    /tmp/rm
    $

    Elijah
    ------
    /usr/bin/busybox rm /tmp/rm

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jon Ribbens@21:1/5 to Paulo da Silva on Thu Oct 13 11:26:14 2022
    On 2022-10-12, Paulo da Silva <p_d_a_s_i_l_v_a_ns@nonetnoaddress.pt> wrote:
    Às 22:38 de 12/10/22, Jon Ribbens escreveu:
    On 2022-10-12, Jon Ribbens <jon+usenet@unequivocal.eu> wrote:
    On 2022-10-12, Paulo da Silva <p_d_a_s_i_l_v_a_ns@nonetnoaddress.pt> wrote: >>>> Às 19:14 de 12/10/22, Jon Ribbens escreveu:
    On 2022-10-12, Paulo da Silva <p_d_a_s_i_l_v_a_ns@nonetnoaddress.pt> wrote:
    Às 05:00 de 12/10/22, Paulo da Silva escreveu:
    Hi!

    The simple question: How do I find the full path of a shell command >>>>>>> (linux), i.e. how do I obtain the corresponding of, for example, >>>>>>> "type rm" in command line?

    The reason:
    I have python program that launches a detached rm. It works pretty well >>>>>>> until it is invoked by cron! I suspect that for cron we need to specify >>>>>>> the full path.
    Of course I can hardcode /usr/bin/rm. But, is rm always in /usr/bin? >>>>>>> What about other commands?

    Thank you all who have responded so far.
    I think that the the suggestion of searching the PATH env seems the best.
    Another thing that I thought of is that of the 'which', but, to avoid >>>>>> the mentioned recurrent problem of not knowing where 'which' is I would >>>>>> use 'type' instead. 'type' is a bash (sh?) command.

    If you're using subprocess.run / subprocess.Popen then the computer is >>>>> *already* searching PATH for you.
    Yes, and it works out of cron.
    Your problem must be that your cron
    job is being run without PATH being set, perhaps you just need to edit >>>>> your crontab to set PATH to something sensible.
    I could do that, but I am using /etc/cron.* for convenience.

    Or just hard-code your
    program to run '/bin/rm' explicitly, which should always work (unless >>>>> you're on Windows, of course!)
    It can also be in /bin, at least.

    I assume you mean /usr/bin. But it doesn't matter. As already
    discussed, even if 'rm' is in /usr/bin, it will be in /bin as well
    (or /usr/bin and /bin will be symlinks to the same place).

    A short idea is to just check /bin/rm and /usr/bin/rm, but I prefer
    searching thru PATH env. It only needs to do that once.

    I cannot think of any situation in which that will help you. But if for
    some reason you really want to do that, you can use the shutil.which()
    function from the standard library:

    >>> import shutil
    >>> shutil.which('rm')
    '/usr/bin/rm'

    Actually if I'm mentioning shutil I should probably mention
    shutil.rmtree() as well, which does the same as 'rm -r', without
    needing to find or run any other executables.
    Except that you can't have parallel tasks, at least in an easy way.
    Using Popen I just launch rm's and end the script.

    [threading.Thread(target=shutil.rmtree, args=(item,)).start()
    for item in items_to_delete]

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mats Wichmann@21:1/5 to Paulo da Silva on Thu Oct 13 08:27:23 2022
    On 10/12/22 14:51, Paulo da Silva wrote:
    Às 19:14 de 12/10/22, Jon Ribbens escreveu:
    On 2022-10-12, Paulo da Silva <p_d_a_s_i_l_v_a_ns@nonetnoaddress.pt>
    wrote:
    Às 05:00 de 12/10/22, Paulo da Silva escreveu:
    Hi!

    The simple question: How do I find the full path of a shell command
    (linux), i.e. how do I obtain the corresponding of, for example,
    "type rm" in command line?

    The reason:
    I have python program that launches a detached rm. It works pretty well >>>> until it is invoked by cron! I suspect that for cron we need to specify >>>> the full path.
    Of course I can hardcode /usr/bin/rm. But, is rm always in /usr/bin?
    What about other commands?

    Thank you all who have responded so far.
    I think that the the suggestion of searching the PATH env seems the
    best.
    Another thing that I thought of is that of the 'which', but, to avoid
    the mentioned recurrent problem of not knowing where 'which' is I would
    use 'type' instead. 'type' is a bash (sh?) command.

    If you're using subprocess.run / subprocess.Popen then the computer is
    *already* searching PATH for you.
    Yes, and it works out of cron.
    Your problem must be that your cron
    job is being run without PATH being set, perhaps you just need to edit
    your crontab to set PATH to something sensible.
    I could do that, but I am using /etc/cron.* for convenience.

    Or just hard-code your
    program to run '/bin/rm' explicitly, which should always work (unless
    you're on Windows, of course!)
    It can also be in /bin, at least.
    A short idea is to just check /bin/rm and /usr/bin/rm, but I prefer searching thru PATH env. It only needs to do that once.

    I've read quite a bit of this thread without completely understanding
    the actual problem.

    Crontabs have always been good at exposing the problem of "is my program expecting something to be set up which isn't guaranteed?" - usually environment variables, of which PATH is one. "But it worked from my
    login shell....".

    Python's standard library has a tool for you:

    shutil.which = which(cmd, mode=1, path=None)
    Given a command, mode, and a PATH string, return the path which
    conforms to the given mode on the PATH, or None if there is no such
    file.

    `mode` defaults to os.F_OK | os.X_OK. `path` defaults to the result
    of os.environ.get("PATH"), or can be overridden with a custom search
    path.



    Since cron usually runs in a minimal environment, you should be able to
    use this to supply a decent value for PATH, look up the command you
    need, and then use that path to launch the command - or fail in some
    sort of graceful way if not found, so you can hear about it and make corrections.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Michael Torrie@21:1/5 to Paulo da Silva on Thu Oct 13 17:24:06 2022
    On 10/11/22 22:00, Paulo da Silva wrote:
    Hi!

    The simple question: How do I find the full path of a shell command
    (linux), i.e. how do I obtain the corresponding of, for example,
    "type rm" in command line?

    The reason:
    I have python program that launches a detached rm. It works pretty well
    until it is invoked by cron! I suspect that for cron we need to specify
    the full path.
    Of course I can hardcode /usr/bin/rm. But, is rm always in /usr/bin?
    What about other commands?

    There are certain standards that suggest where to look. For example,
    there's the Linux Filesystem Hiearchy Standard 3.0: https://refspecs.linuxfoundation.org/FHS_3.0/fhs/ch03s04.html

    In short, you want to hard code /bin for a command like rm. And yes it
    will always be in /bin on any standard Linux OS.

    Despite modern distros making /bin and /usr/bin the same directory, if
    the target OS is anywhere close to the standard, you can always find the
    basic commands in /bin. I would not hard code any script to use
    /usr/bin for any basic commands and I would not use anything other than
    /bin/sh or /bin/bash as the shell script shebang if you want any sort of portability.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Dan Stromberg@21:1/5 to p_d_a_s_i_l_v_a_ns@nonetnoaddress.p on Fri Oct 14 07:40:14 2022
    On Wed, Oct 12, 2022 at 11:13 AM Paulo da Silva < p_d_a_s_i_l_v_a_ns@nonetnoaddress.pt> wrote:

    Hi!

    The simple question: How do I find the full path of a shell command
    (linux), i.e. how do I obtain the corresponding of, for example,
    "type rm" in command line?

    The reason:
    I have python program that launches a detached rm. It works pretty well
    until it is invoked by cron! I suspect that for cron we need to specify
    the full path.
    Of course I can hardcode /usr/bin/rm. But, is rm always in /usr/bin?
    What about other commands?

    I like to test my cronjobs with something like:

    env - /usr/local/bin/my-cronjob

    This will empty out the environment, and force you to set $PATH yourself.

    Alternatively, you can "ps axfwwe" (on Linux) to see environment variables,
    and check what the environment of cron (or similar) is. It is this
    environment (mostly) that cronjobs will inherit.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Peter J. Holzer@21:1/5 to Dan Stromberg on Fri Oct 14 18:19:32 2022
    On 2022-10-14 07:40:14 -0700, Dan Stromberg wrote:
    Alternatively, you can "ps axfwwe" (on Linux) to see environment
    variables, and check what the environment of cron (or similar) is. It
    is this environment (mostly) that cronjobs will inherit.

    The simplest (and IMHO also most reliable) way to find out the
    environment a cronjob has is to write a cronjob which just dumps the environment.

    hp

    --
    _ | Peter J. Holzer | Story must make more sense than reality.
    |_|_) | |
    | | | hjp@hjp.at | -- Charles Stross, "Creative writing
    __/ | http://www.hjp.at/ | challenge!"

    -----BEGIN PGP SIGNATURE-----

    iQIzBAABCgAdFiEETtJbRjyPwVTYGJ5k8g5IURL+KF0FAmNJjBQACgkQ8g5IURL+ KF2HEA//TwjE6RXRa2jr9JQGDFrBj9iBcwokE7hj/pnajTa7p3tCWoNbHIY4Gwfk gKbfOPNeMHA0PERXoaWrZ/kHTIZ3nyJehHHtDJGkG9cjvfbPv5WBb4xB1bxNSR60 8csl4LnIJhCma4qWTETfJYGaKGC/Ybn1jOJzOHLcpQa4f/pljE9z1gYN7TZ49YX4 rYqPRyw1InWfA61rgunjZqGO8IerlBMvgUo0aD53khd48gz+4Hr/ZQLRDVYnus31 rNr3Ksd5dVIg+x89KFjFr/XH7c8dU158rCrnslv+bHR/RdK6MZLcFYf2SwLVFE7d Pwx6FfFojD/UVJLyhOV8WazxQj7koTlSzQz7UYb753SdPD6v1G0CZ6lFIJu+snKF ARgPpd1SjTHebcpUBSxz9ZOBkhCVWn+EVSBrjmBEL5wr0bPTRzWOxQOiheyFIJMY ashjEybQ1h1ye6/VV8FA2P+SusJLwaosZR0hORUh2W30NdEYziHce2adKRjJ2C0Z PalRfK3NHR6LtYPek/C7dssPdl6K1va1ZTMu2PBiYUTw+Iq8zPsUU4Y3kzhCqj7e u+2uvyiDwDyZU+UfFO7ihiiXCiIJrIV2YCRmCk8ktQ+XLvGoezx81R7pP46BypG1 /9i59aWZSUGhdyLObPlAA1ivVhRucL6WF9lgEEf
  • From Albert-Jan Roskam@21:1/5 to All on Fri Oct 14 19:57:45 2022
    On Oct 14, 2022 18:19, "Peter J. Holzer" <hjp-python@hjp.at> wrote:

    On 2022-10-14 07:40:14 -0700, Dan Stromberg wrote:
    > Alternatively, you can "ps axfwwe" (on Linux) to see environment
    > variables, and check what the environment of cron (or similar) is.  It
    > is this environment (mostly) that cronjobs will inherit.

    The simplest (and IMHO also most reliable) way to find out the
    environment a cronjob has is to write a cronjob which just dumps the
    environment.

      

    =====
    Lately I've been using systemd timers instead of cronjobs. They are easier
    to debug (journalctl) but require a bit more work to write. Systemd is
    available on Fedora & friends and Debian based systems, maybe more. It has
    no builtin MAILTO. I use an OnFailure stanza to send a Slack message with
    curl instead.
    https://www.freedesktop.org/software/systemd/man/systemd.timer.html
    https://unix.stackexchange.com/questions/278564/cron-vs-systemd-timers

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Andreas Eder@21:1/5 to Paulo da Silva on Sat Oct 15 18:13:32 2022
    On Mi 12 Okt 2022 at 05:00, Paulo da Silva <p_d_a_s_i_l_v_a_ns@nonetnoaddress.pt> wrote:

    The simple question: How do I find the full path of a shell command
    (linux), i.e. how do I obtain the corresponding of, for example,
    "type rm" in command line?

    The reason:
    I have python program that launches a detached rm. It works pretty well
    until it is invoked by cron! I suspect that for cron we need to specify
    the full path.
    Of course I can hardcode /usr/bin/rm. But, is rm always in /usr/bin?
    What about other commands?

    Why not just use os.unlink ?

    'Andreas

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Dan Stromberg@21:1/5 to cs@cskk.id.au on Sat Oct 15 20:49:55 2022
    On Wed, Oct 12, 2022 at 9:57 PM Cameron Simpson <cs@cskk.id.au> wrote:

    On 13Oct2022 03:25, Paulo da Silva <p_d_a_s_i_l_v_a_ns@nonetnoaddress.pt> wrote:
    There is another problem involved. The script, works fine except when >launched by cron! Why?

    Record the script output:

    # record all output
    exec >/tmp/script.$$.out 2>&1
    # dump the envionment
    env | sort
    # turn on execution tracing
    set -x
    ... rest of the script

    and have a look afterwards. Cron's environment is very minimal. This
    will show you what's in it.


    Careful. On some systems if someone restarts the cron daemon, it could
    pick up a larger environment than after being started on boot.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Barry@21:1/5 to All on Sun Oct 16 17:21:03 2022
    On 16 Oct 2022, at 04:53, Dan Stromberg <drsalists@gmail.com> wrote:

    On Wed, Oct 12, 2022 at 9:57 PM Cameron Simpson <cs@cskk.id.au> wrote:

    On 13Oct2022 03:25, Paulo da Silva <p_d_a_s_i_l_v_a_ns@nonetnoaddress.pt> >>> wrote:
    There is another problem involved. The script, works fine except when
    launched by cron! Why?

    Record the script output:

    # record all output
    exec >/tmp/script.$$.out 2>&1
    # dump the envionment
    env | sort
    # turn on execution tracing
    set -x
    ... rest of the script

    and have a look afterwards. Cron's environment is very minimal. This
    will show you what's in it.


    Careful. On some systems if someone restarts the cron daemon, it could
    pick up a larger environment than after being started on boot.

    That have to a old system that does not use systemd.
    Is there a specific system that still does this?

    Barry

    --
    https://mail.python.org/mailman/listinfo/python-list


    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Peter J. Holzer@21:1/5 to Barry on Sun Oct 16 19:16:34 2022
    On 2022-10-16 17:21:03 +0100, Barry wrote:
    On 16 Oct 2022, at 04:53, Dan Stromberg <drsalists@gmail.com> wrote:

    On Wed, Oct 12, 2022 at 9:57 PM Cameron Simpson <cs@cskk.id.au> wrote:

    On 13Oct2022 03:25, Paulo da Silva <p_d_a_s_i_l_v_a_ns@nonetnoaddress.pt> >>> wrote:
    There is another problem involved. The script, works fine except when
    launched by cron! Why?
    [... script deleted ...]
    Cron's environment is very minimal. This will show you what's in
    it.

    Careful. On some systems if someone restarts the cron daemon, it could pick up a larger environment than after being started on boot.

    That have to a old system that does not use systemd.

    Systemd is specific to Linux - and not even used by all Linux
    distributions.

    Is there a specific system that still does this?

    Not sure. Some Unixes I've used in the past (probably including some
    Linux distributions) had this problem. So you had to be a bit careful
    when restarting daemons from the command line. I think the sysVinit
    system used by most Linux distributions before systemd did clean up the environment if you used it correctly (but I'm not sure and have no
    system anymore to test it). I haven't used Solaris or HP/UX in a long
    time (and other Unixes even longer) so I don't know what they do these
    days. And I've never used MacOS, I just know that they've used a system
    of their own long before systemd.

    Anyway he doesn't have to restart cron to add a cron-job (nor for any
    other reason during normal operation), so what happens if you manually
    restart cron is almost certainly irrelevant for the OP.

    hp

    --
    _ | Peter J. Holzer | Story must make more sense than reality.
    |_|_) | |
    | | | hjp@hjp.at | -- Charles Stross, "Creative writing
    __/ | http://www.hjp.at/ | challenge!"

    -----BEGIN PGP SIGNATURE-----

    iQIzBAABCgAdFiEETtJbRjyPwVTYGJ5k8g5IURL+KF0FAmNMPG0ACgkQ8g5IURL+ KF0L+A/8CPBQII7THsRIMHjD4iITuFyC8CtXPPR9rLqi8rJnY3vBaERrZfX0DUou tKeLh0Iz3A3NQmy3BgEY4Cpbr8TDxi0FerR0awdn/kS4ru1AkpDBNYMpNtS6OTVz HfHrOvSHeAMPmGhIsjhm9ssLSsvroVz6DhsT7rJZUDX4fRp7oLJiChQObrVvwdE2 7Osm/9h5f1O+jgHNSJ3RMBYhESzYZUPdda8Wsc+tbP5wLBvuYvGC/Nyglwk+QKJg gttkrL/r2/rMLuAnVcBnPg8V+BnrVICEWk5Xu9AizMez7XwWQ1NzBBgiaZfeVePa 618F1/bX/tUd8k+bw06XfMxbomfPKzpfNzLERNM419wadhqBzeovZy6BmZXqbOaq KBe4Nj3HqlVnhIl+pm/N6fKcSPCjwAZlSlUtcbUNEezko74W5BbT71eJY3kfb4S6 ygyy6g3SAh5CpaCn4H6Gnn57pUspy1TRydw/sA1G0UEbyObYcKSzC9T+2NbPorbu rB9jFn+oDLjvDAI2S/xGuS2lDIJUoa0uB3cnYR64UVAwjwq1e/WhFa6s4PeCHLQ6 HPYp2ndDMnt1KpHpny/TvPiCZ77f960n601k8X6LuGLP5qMY6P/rtn8xI446fPVH t3oCOBnPF4jGN9o3RWnybpK7O1rNQvLcpWPrsHE
  • From Grant Edwards@21:1/5 to Andreas Eder on Mon Oct 17 10:55:08 2022
    On 2022-10-15, Andreas Eder <a_eder_muc@web.de> wrote:
    On Mi 12 Okt 2022 at 05:00, Paulo da Silva <p_d_a_s_i_l_v_a_ns@nonetnoaddress.pt> wrote:

    The simple question: How do I find the full path of a shell command
    (linux), i.e. how do I obtain the corresponding of, for example,
    "type rm" in command line?

    The reason:
    I have python program that launches a detached rm. It works pretty
    well until it is invoked by cron! I suspect that for cron we need
    to specify the full path.

    Why not just use os.unlink ?

    Because he's using 'rm' to recursively remove a large directory tree
    many levels deep.

    One might think that could be done by

    os.removedirs(name)
    Remove directories recursively. [...]

    But it doesn't appear so from the description:

    Works like rmdir() except that, if the leaf directory is
    successfully removed, removedirs() tries to successively remove
    every parent directory mentioned in path until an error is raised
    (which is ignored, because it generally means that a parent
    directory is not empty). For example, os.removedirs('foo/bar/baz')
    will first remove the directory 'foo/bar/baz', and then remove
    'foo/bar' and 'foo' if they are empty. Raises OSError if the leaf
    directory could not be successfully removed.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)