Mailing List Archive

Pipe transport and script (shebang)
Hi all,

recently i decide to improve my pipe transport for reports processing
to allow relative commands and i go into problems. It was worked
without problems with absolute script path for long time. I solved it,
but i want to know why that happens...

The only changes which i did, are -- i add path option to transport:

path = /my/scripts/path

I changed command name to relative (without path) in redirect router:

data = |script_name.py one_arg

After message arrived, it fail to run that script, with output:

reports_pipe transport output: /usr/bin/env: 'python3': No such
file or directory

I had that in shebang, after i changed shebang to point directly to
/usr/bin/python3, it starts to work again.

I tried to emulate that from shell by setting PATH variable to the same
value as in transport, then i tried to clear it at all, but scripts runs
without problem, i tried to find something in env's man page, but i
fail...

Thus i am curios why that was not problem with full script path but it
is problem with relative script path. Can please someone explain me
that?

regards

--
Slavko
https://www.slavino.sk
Re: Pipe transport and script (shebang) [ In reply to ]
On Mon, 28 Aug 2023, Slavko via Exim-users wrote:

> Hi all,
>
> recently i decide to improve my pipe transport for reports processing
> to allow relative commands and i go into problems. It was worked
> without problems with absolute script path for long time. I solved it,
> but i want to know why that happens...
>
> The only changes which i did, are -- i add path option to transport:
>
> path = /my/scripts/path
>
> I changed command name to relative (without path) in redirect router:
>
> data = |script_name.py one_arg
>
> After message arrived, it fail to run that script, with output:
>
> reports_pipe transport output: /usr/bin/env: 'python3': No such
> file or directory
>
> I had that in shebang, after i changed shebang to point directly to
> /usr/bin/python3, it starts to work again.
>
> I tried to emulate that from shell by setting PATH variable to the same
> value as in transport, then i tried to clear it at all, but scripts runs
> without problem, i tried to find something in env's man page, but i
> fail...
>
> Thus i am curios why that was not problem with full script path but it
> is problem with relative script path. Can please someone explain me
> that?

I guess that and your first change meant that /usr/bin/env could no longer
find pthyon3.

Some say that using /usr/bin/env in shebang helps, but others say it makes
things worse. With distributions changing from the default python
from python2 to python3 the mess got more tangled. Find something that
works on your systems and stick with it.


--
Andrew C. Aitchison Kendal, UK
andrew@aitchison.me.uk

--
## subscription configuration (requires account):
## https://lists.exim.org/mailman3/postorius/lists/exim-users.lists.exim.org/
## unsubscribe (doesn't require an account):
## exim-users-unsubscribe@lists.exim.org
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/
Re: Pipe transport and script (shebang) [ In reply to ]
On Mon, 28 Aug 2023, Andrew C Aitchison wrote:

> On Mon, 28 Aug 2023, Slavko via Exim-users wrote:
>
>> Hi all,
>>
>> recently i decide to improve my pipe transport for reports processing
>> to allow relative commands and i go into problems. It was worked
>> without problems with absolute script path for long time. I solved it,
>> but i want to know why that happens...
>>
>> The only changes which i did, are -- i add path option to transport:
>>
>> path = /my/scripts/path
>>
>> I changed command name to relative (without path) in redirect router:
>>
>> data = |script_name.py one_arg
>>
>> After message arrived, it fail to run that script, with output:
>>
>> reports_pipe transport output: /usr/bin/env: 'python3': No such
>> file or directory
>>
>> I had that in shebang, after i changed shebang to point directly to
>> /usr/bin/python3, it starts to work again.
>>
>> I tried to emulate that from shell by setting PATH variable to the same
>> value as in transport, then i tried to clear it at all, but scripts runs
>> without problem, i tried to find something in env's man page, but i
>> fail...
>>
>> Thus i am curios why that was not problem with full script path but it
>> is problem with relative script path. Can please someone explain me
>> that?
>
> I guess that and your first change meant that /usr/bin/env could no longer
> find pthyon3.

Sorry, I meant to add
because env uses path.

> Some say that using /usr/bin/env in shebang helps, but others say it makes
> things worse. With distributions changing from the default python from
> python2 to python3 the mess got more tangled. Find something that works on
> your systems and stick with it.
>
>
> --
> Andrew C. Aitchison Kendal, UK
> andrew@aitchison.me.uk
>

--
Andrew C. Aitchison Kendal, UK
andrew@aitchison.me.uk

--
## subscription configuration (requires account):
## https://lists.exim.org/mailman3/postorius/lists/exim-users.lists.exim.org/
## unsubscribe (doesn't require an account):
## exim-users-unsubscribe@lists.exim.org
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/
Re: Pipe transport and script (shebang) [ In reply to ]
D?a 28. augusta 2023 12:01:49 UTC používate? Andrew C Aitchison <andrew@aitchison.me.uk> napísal:

>> I guess that and your first change meant that /usr/bin/env could no longer find pthyon3.
>
>Sorry, I meant to add
> because env uses path.

Yes, that was my first idea too, but as i wrote, already, i set PATH
manually in shell, then i run:

/usr/bin/env python3

And python was run... I tried to verify that this PATH is used too:

/usr/bin/env -S /bin/echo $PATH

which returns empty line (after unset).

Thus IMO the PATH itself is not an issue, but i know near nothing
how exim run that command, except that it doesn't use shell.

regards


--
Slavko
https://www.slavino.sk/

--
## subscription configuration (requires account):
## https://lists.exim.org/mailman3/postorius/lists/exim-users.lists.exim.org/
## unsubscribe (doesn't require an account):
## exim-users-unsubscribe@lists.exim.org
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/
Re: Pipe transport and script (shebang) [ In reply to ]
On 2023-08-28 Slavko via Exim-users <exim-users@lists.exim.org> wrote:
[...]
> The only changes which i did, are -- i add path option to transport:

> path = /my/scripts/path

Hello,

So you tell it to search *exclusively* there.

> I changed command name to relative (without path) in redirect router:

> data = |script_name.py one_arg

> After message arrived, it fail to run that script, with output:

> reports_pipe transport output: /usr/bin/env: 'python3': No such
> file or directory

... and the shebang line "#!/usr/bin/env python3" tells the program
loader to run /usr/bin/env with arg "python3", and env searches for
python3 in PATH. It probably doeds not live in /my/scripts/path.

> I had that in shebang, after i changed shebang to point directly to
> /usr/bin/python3, it starts to work again.

> I tried to emulate that from shell by setting PATH variable to the same
> value as in transport, then i tried to clear it at all, but scripts runs
> without problem,
[...]

Your testing was faulty.

ametzler@argenau:~$ cat /tmp/hello
#!/usr/bin/env python3
print("Hello world!")
ametzler@argenau:~$ /tmp/hello
Hello world!
ametzler@argenau:~$ env PATH="/nopython3here" /tmp/hello
/usr/bin/env: ‘python3’: No such file or directory
ametzler@argenau:~$ env PATH="/nopython3here:/usr/bin" /tmp/hello
Hello world!

cu Andreas

--
## subscription configuration (requires account):
## https://lists.exim.org/mailman3/postorius/lists/exim-users.lists.exim.org/
## unsubscribe (doesn't require an account):
## exim-users-unsubscribe@lists.exim.org
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/
Re: Pipe transport and script (shebang) [ In reply to ]
On 28/08/2023 11:57, Slavko via Exim-users wrote:
> I tried to emulate that from shell by setting PATH variable to the same
> value as in transport, then i tried to clear it at all, but scripts runs
> without problem, i tried to find something in env's man page, but i
> fail...

Does your shell auto-export a set variable to the environment?
Or does it stay as an internal variable, leaving the PATH
in the environment unchanged?
--
Cheers,
Jeremy


--
## subscription configuration (requires account):
## https://lists.exim.org/mailman3/postorius/lists/exim-users.lists.exim.org/
## unsubscribe (doesn't require an account):
## exim-users-unsubscribe@lists.exim.org
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/
Re: Pipe transport and script (shebang) [ In reply to ]
D?a 29. augusta 2023 16:34:24 UTC používate? Jeremy Harris via Exim-users <exim-users@lists.exim.org> napísal:

>Does your shell auto-export a set variable to the environment?
>Or does it stay as an internal variable, leaving the PATH
>in the environment unchanged?

I don't know how bash deals with autoexport, but i find diference:

+ when i unset PATH variable, the env can find python (and others)
+ when i set PATH to empty (or other) value, the env fails

Thus i guess, that while result is the same (no value) the env uses
some default path(s) in case when PATH is not set. I guess about
env's default, as bash itself complains about command(s) in both
cases.

Thanks to both, you are pointing me to find/understand the
reason ;-)

regards


--
Slavko
https://www.slavino.sk/

--
## subscription configuration (requires account):
## https://lists.exim.org/mailman3/postorius/lists/exim-users.lists.exim.org/
## unsubscribe (doesn't require an account):
## exim-users-unsubscribe@lists.exim.org
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/
Re: Pipe transport and script (shebang) [ In reply to ]
Hello!

On Tue, 29 Aug 2023 at 17:14:33 (+0000), Slavko via Exim-users wrote:

> I don't know how bash deals with autoexport, but i find diference:

> + when i unset PATH variable, the env can find python (and others)
> + when i set PATH to empty (or other) value, the env fails

"undefined var" != "var with the empty value" and hence the behavior is
different.

> Thus i guess, that while result is the same (no value) the env uses
> some default path(s) in case when PATH is not set. I guess about
> env's default, as bash itself complains about command(s) in both
> cases.

When PATH is not set, `env` relies (by means of standard libs) upon
default location of binary files (defined by means of standard libs).
This value may vary across different OS's.
You can verify this value by running `getconf PATH` on the target system.

--
George L. Yermulnik
[YZ-RIPE]

--
## subscription configuration (requires account):
## https://lists.exim.org/mailman3/postorius/lists/exim-users.lists.exim.org/
## unsubscribe (doesn't require an account):
## exim-users-unsubscribe@lists.exim.org
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/