Netgate Discussion Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Search
    • Register
    • Login

    [SOLVED]: Execute php from a Bash environment

    Scheduled Pinned Locked Moved General pfSense Questions
    10 Posts 2 Posters 4.3k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • J
      Javote
      last edited by

      Hello everyone!

      First! Congratulations! Excellent software, and great community!

      Now, for the real reason of the post.

      I have a script in bash that I execute as follows:

      # bash ./bash_script.sh
      

      Inside the script I make a call to php executable as follows:

      
      php -f /path/to/helper/php_file.php
      
      

      The problem is that the php executable is not found.
      If I log to SSH console and execute the same line, it works.
      If on the same console I launch a bash shell and execute de same line, it fails.

      My guess is that bash is forbidden it's access to php.

      Is there a way I can execute my php script from my bash script?

      Thanks!

      Edit: TL;DR, I installed bash using: pkg install bash

      1 Reply Last reply Reply Quote 0
      • D
        doktornotor Banned
        last edited by

        It will work a whole lot better with /usr/local/bin/php

        1 Reply Last reply Reply Quote 0
        • J
          Javote
          last edited by

          @doktornotor:

          It will work a whole lot better with /usr/local/bin/php

          It won't, there is no such file. Also, which php does not work. PATH variable seems OK.

          bash: /usr/local/bin/php: No such file or directory
          
          
          REMOTEHOST=xxxxx
          HOST=xxxx
          SHELL=/bin/sh
          TERM=xterm
          CLICOLOR=true
          SSH_CLIENT=xxxx
          LD_32_LIBRARY_PATH=/usr/local/lib
          SSH_TTY=/dev/pts/0
          GROUP=wheel
          USER=root
          HOSTTYPE=FreeBSD
          FTP_PASSIVE_MODE=YES
          LSCOLORS=exfxcxdxbxegedabagacad
          PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/root/bin
          MAIL=/var/mail/root
          BLOCKSIZE=K
          PWD=/root
          LD_32_PBIPRELOAD=/usr/pbi/.pbi_preload32.so
          LD_ELF_HINTS_PATH=/var/run/ld-elf.so.hints.freeradius-amd64
          LD_PBIPRELOAD=/usr/pbi/.pbi_preload.so
          SHLVL=2
          HOME=/root
          OSTYPE=FreeBSD
          VENDOR=amd
          MACHTYPE=x86_64
          LOGNAME=root
          SSH_CONNECTION=xxxx
          LD_32_ELF_HINTS_PATH=/var/run/ld-elf32.so.hints.freeradius-amd64
          PBI_RUNDIR=/usr/pbi/freeradius-amd64
          _=/usr/bin/env
          
          

          Looking at ti, I get the feeling all these references to freeradius might be causing some trouble!

          1 Reply Last reply Reply Quote 0
          • D
            doktornotor Banned
            last edited by

            Where's no such file? What are you talking about?

            
            $ /usr/local/bin/php
            /usr/local/bin/php: ELF 64-bit LSB executable, x86-64, version 1 (FreeBSD), dynamically linked, interpreter /libexec/ld-elf.so.1, for FreeBSD 10.1, not stripped
            
            

            Fix your system. Plus, why on earth you need bash for this? What's wrong with /bin/sh? Also, stop relying on PATH being set anywhere in your scripts. Especially the remotely executed ones.

            1 Reply Last reply Reply Quote 0
            • J
              Javote
              last edited by

              @doktornotor:

              Where's no such file? What are you talking about?

              Thats what I get from trying to execute php from bash!

              @doktornotor:

              Fix your system. Plus, why on earth you need bash for this? What's wrong with /bin/sh? Also, stop relying on PATH being set anywhere in your scripts. Especially the remotely executed ones.

              I will gladly fix my system. Will you help me?

              I use which command to get the location (this might be using PATH), but it returns empty. How else can I make my script portable?
              Either way, php will not execute (it will not be found).

              Regards

              1 Reply Last reply Reply Quote 0
              • D
                doktornotor Banned
                last edited by

                Without PHP, your pfSense would be unbootable. Post your code here if you want any meaningful help.

                1 Reply Last reply Reply Quote 0
                • J
                  Javote
                  last edited by

                  I think I got to something!

                  From sh shell:

                  
                  [2.2.3-RELEASE][root@pfsense]/root: which bash
                  /usr/local/bin/bash
                  
                  

                  But when I go check this bash executable i get that it is a symlink to a bash from freeradius:

                  
                  [2.2.3-RELEASE][root@pfsense]/root: ls -l /usr/local/bin/bash
                  lrwxr-xr-x  1 root  wheel  34 Oct 29 16:29 /usr/local/bin/bash -> /usr/pbi/freeradius-amd64/bin/bash
                  
                  

                  So I am thinking the bash, gets me inside a jail, because when I am inside bash and list /usr/local/bin I get this:

                  
                  [root@pfsense ~]# ls /usr/local/bin/
                  2to3-2.7         corelist         droplang         gettext          k5srvutil        ktutil           ldapsearch       mysqlaccess      ngettext         pg_config        pod2man          ptar             radcrypt         reindexdb        splain
                  a2p              cpan             dropuser         gettext.sh       kadmin           kvno             ldapurl          mysqlaccess.conf openssl          pg_dump          pod2text         ptardiff         radeapclient     rlm_dbm_cat      uuclient
                  bash             cpan2dist        ecpg             gss-client       kdestroy         ldapadd          ldapwhoami       mysqladmin       perl             pg_dumpall       pod2usage        ptargrep         radlast          rlm_dbm_parser   vacuumdb
                  bashbug          cpanp            enc2xs           h2ph             kinit            ldapcompare      libnetcfg        mysqlbinlog      perl5            pg_isready       podchecker       pydoc2.7         radsniff         rlm_ippool_tool  xml2-config
                  c2ph             cpanp-run-perl   envsubst         h2xs             klist            ldapdelete       msql2mysql       mysqlcheck       perl5.18.4       pg_restore       podselect        python2.7        radsqlrelay      s2p              xmlcatalog
                  c_rehash         createdb         find2perl        idle2.7          kpasswd          ldapexop         mysql            mysqldump        perlbug          piconv           prove            python2.7-config radtest          sclient          xmllint
                  clusterdb        createlang       gdbm_dump        indexinfo        krb5-config      ldapmodify       mysql_config     mysqlimport      perldoc          pl2pm            psed             rad_counter      radwho           shasum           xsubpp
                  compile_et       createuser       gdbm_load        instmodsh        ksu              ldapmodrdn       mysql_find_rows  mysqlshow        perlivp          pod2html         psql             radclient        radzap           sim_client       zipdetails
                  config_data      dropdb           gdbmtool         json_pp          kswitch          ldappasswd       mysql_waitpid    mysqlslap        perlthanks       pod2latex        pstruct          radconf2xml      rbash            smbencrypt
                  
                  

                  Which is the same as I get when I list /usr/pbi/freeradius-amd64/local/bin

                  But really different from when I list /usr/local/bin from the sh prompt:

                  
                  [2.2.3-RELEASE][root@pfsense]/root: ls /usr/local/bin/
                  3gstat                         c-icap                         filterparser.php               lua50                          php                            radtest                        slowdownpipe.sh                zabbix_get
                  3gstats.php                    c-icap-client                  gettext                        lua50c                         ping_hosts.sh                  radwho                         smbencrypt                     zabbix_sender
                  7z                             captiveportal_gather_stats.php gettext.sh                     lua50c51                       pki                            radzap                         sqlite3                        zip
                  7za                            check_ip.php                   gogoc                          mail.php                       rad_counter                    rate                           sudo                           zipcloak
                  7zr                            cpdup                          hifnstats                      minicron                       radclient                      rbash                          sudoedit                       zipnote
                  athstats                       cryptokeytest                  host                           ngettext                       radconf2xml                    rlm_dbm_cat                    sudoreplay                     zipsplit
                  bash                           cryptostats                    iftop                          nslookup                       radcrypt                       rlm_dbm_parser                 ubsecstats
                  bashbug                        cryptotest                     ipmitool                       nsupdate                       radeapclient                   rlm_ippool_tool                viconfig
                  beep                           dig                            ipsecstats                     pcre-config                    radlast                        rrdtool                        voucher
                  beep.sh                        easyrule                       isc-config.sh                  pcregrep                       radsniff                       runmsntp.sh                    wol
                  bind9-config                   envsubst                       links                          pcretest                       radsqlrelay                    safestats                      xmllint
                  
                  

                  My conclusion is that freeradius installs its own version of bash that gets inside the jail!

                  I would have to install bash from a bash package then, but I worry that freeradius will stop working!

                  1 Reply Last reply Reply Quote 0
                  • D
                    doktornotor Banned
                    last edited by

                    Rewrite your top secret code to use /bin/sh.

                    1 Reply Last reply Reply Quote 0
                    • J
                      Javote
                      last edited by

                      @doktornotor:

                      Rewrite your top secret code to use /bin/sh.

                      It's not that it is TOP-SECRET, at this point the code is noise. I won't rewrite because it is really long.

                      You are missing the problem, that is the bash symlink to freeradius. I appreciate your help.

                      I resolved installing bash using

                      
                      pkg install bash
                      
                      

                      Regards

                      1 Reply Last reply Reply Quote 0
                      • D
                        doktornotor Banned
                        last edited by

                        No, I'm not missing the problem. Any PBI clusterfuck is unusable for similar tasks. (Why are you writing bash-specific scripts for system that has no bash by default still goes beyond me.)

                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post
                        Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.