• script under launchd

    From Dr Eberhard Lisse@21:1/5 to All on Tue Feb 8 14:09:15 2022
    Hi,

    how can a (bash) script find out whether it runs under launchd?

    el
    --
    To email me replace 'nospam' with 'el'

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lewis@21:1/5 to Dr Eberhard Lisse on Tue Feb 8 18:09:37 2022
    In message <j6f4rcFu3g7U2@mid.individual.net> Dr Eberhard Lisse <nospam@lisse.NA> wrote:
    Hi,

    how can a (bash) script find out whether it runs under launchd?

    the usual way to see how a script was launched is to check the EUID, but
    I am not sure that will tell you with launchd

    For example, to check if the script was launched by root:

    if [[ $EUID -ne 0 ]]; then
    echo "root user required"
    exit 1
    fi

    --
    Y'all need to get together and woman up.
    I think you mean man up.
    No, y'all have been manning up for a while, Look where that's
    got you.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Dr Eberhard Lisse@21:1/5 to Lewis on Thu Feb 10 09:39:33 2022
    Thank you for answering a question that I did not ask, the answer to
    which I knew and was not helpful. Which was unsurprising.

    As the script is used by the User (only), $EUID is the same whether
    started interactively or by launchd.

    However, for those who might be interested, I found that you can easily
    put something like

    <key>EnvironmentVariables</key>
    <dict>
    <key>RUNNING_UNDER_LAUNCHD</key>
    <string>1</string>
    </dict>
    </key>

    into the plist and then check $RUNNING_UNDER_LAUNCHD.

    If yo want to be sure you can set RUNNING_UNDER_LAUNCHD to 0 in .bashrc.


    Then of course one can check for $PPID which is 1 if turned loose by
    launchd.


    And then finally is $XPC_SERVICE_NAME which you (can) set with

    <key>Label</key>
    <string>na.lisse.whatever.run</string>

    in the plist and on an interactive shell is 0.


    So, bottom line, RTFM :-)-O

    el

    On 08/02/2022 20:09, Lewis wrote:
    In message <j6f4rcFu3g7U2@mid.individual.net> Dr Eberhard Lisse <nospam@lisse.NA> wrote:
    Hi,

    how can a (bash) script find out whether it runs under launchd?

    the usual way to see how a script was launched is to check the EUID,
    but I am not sure that will tell you with launchd

    For example, to check if the script was launched by root:

    if [[ $EUID -ne 0 ]]; then
    echo "root user required"
    exit 1
    fi


    --
    To email me replace 'nospam' with 'el'

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lewis@21:1/5 to Dr Eberhard Lisse on Thu Feb 10 14:47:37 2022
    In message <j6jtpoFri67U1@mid.individual.net> Dr Eberhard Lisse <nospam@lisse.NA> wrote:
    Thank you for answering a question that I did not ask, the answer to
    which I knew and was not helpful. Which was unsurprising.

    I apologize for attempting to help you. It will not ever happen again.

    --
    I don't believe there's a power in the 'verse can stop Kaylee from
    bein' cheerful. Sometimes you just wanna duct-tape her mouth and
    dump her in the hold for a month.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Dr Eberhard Lisse@21:1/5 to Lewis on Fri Feb 11 12:35:54 2022
    Never happened before either.

    el

    On 10/02/2022 16:47, Lewis wrote:
    In message <j6jtpoFri67U1@mid.individual.net> Dr Eberhard Lisse <nospam@lisse.NA> wrote:
    Thank you for answering a question that I did not ask, the answer to
    which I knew and was not helpful. Which was unsurprising.

    I apologize for attempting to help you. It will not ever happen
    again.


    --
    To email me replace 'nospam' with 'el'

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