L
L
Leonid2015-08-06 09:58:27
Perl
Leonid, 2015-08-06 09:58:27

Why doesn't env perl work in rc.d scripts?

FreeBSD 8.2. I'm trying to write an rc.d script to run a perl script on system startup.
perl script:

#!/usr/bin/env perl
print "Hello World!\n";

rc.d script:
#!/bin/sh
#
# PROVIDE: mytest
# KEYWORD: FreeBSD

. /etc/rc.subr

name="mytest"
rcvar=`set_rcvar`
start_cmd="mytest_start"

mytest_start ()
{
        out=`/home/user/mytest 2>&1`
        echo $? > /tmp/file
        echo $out >> /tmp/file
}

load_rc_config $name
run_rc_command "$1"

When I reboot I see:
cat /tmp/file
127
env: perl: No such file or directory

At the same time, /usr/local/etc/rc.d/mytest start works fine.
If you set the #!/usr/local/bin/perl interpreter in a perl script, it works fine.
As far as I understand, the problem is that env does not know perl at the time of the script execution attempt. Played around with REQUIRE - didn't help.
Push in the right direction, please.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
Leonid, 2015-08-06
@zzevaka

At the time of rc.d script execution:
PATH=/sbin:/bin:/usr/sbin:/usr/bin
perl is installed in /usr/local/bin/
So far I solved the problem like this:
superuser.com/questions/224974/how -do-i-add-a-loca...
Before executing the command in the rc.d script, add the required path to PATH:

PATH=${PATH}:/usr/local/bin
export PATH

The solution is not elegant, because with this approach, all the beauty of declaring the interpreter through env is lost.
thanks mureevms !

M
mureevms, 2015-08-06
@mureevms

Find out where you have the pearl installed:

whereis perl
perl: /usr/bin/perl /usr/local/man/man1/perl.1.gz /usr/src/contrib/file/Magdir/perl

And point to it at the beginning of the script:
#!/usr/bin/perl
Сам скрипт

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question