How can I run php scripts from a shell script?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • john@munsey.net

    How can I run php scripts from a shell script?

    Newbie about this stuff.

    I want to run some php scripts from a shell script(bash?)

    the php script i want to run is this:
    test.php

    and it's path is this:
    home/virtual/blahblah.com/home/abc/mainwebsite_htm l/bluhbluh/dbtest/

    1. How would I creat the shell script?
    2. How would I execute it?

    I have already tried ot figure it out with no success.

    I have php 4.2.2

    Thanks

  • Colin McKinnon

    #2
    Re: How can I run php scripts from a shell script?

    john@munsey.net spilled the following:
    [color=blue]
    > Newbie about this stuff.
    >
    > I want to run some php scripts from a shell script(bash?)
    >
    > the php script i want to run is this:
    > test.php
    >
    > and it's path is this:
    > home/virtual/blahblah.com/home/abc/mainwebsite_htm l/bluhbluh/dbtest/
    >
    > 1. How would I creat the shell script?
    > 2. How would I execute it?
    >
    > I have already tried ot figure it out with no success.
    >
    > I have php 4.2.2[/color]

    PHP can be compiled as a standalone binary or as a module for various
    webservers. The former can also be used in conjunction with a webserver.
    Life's a lot simpler if you have the standalone binary. I use SuSE mostly -
    it's mod_php rpm includes both the module and standalone interpreter. If
    you have got it on your machine it'll probably be called 'php' and is
    likely to be in /usr/bin or /usr/local/bin. First thing to try would be
    `which php` - then try looking in the directories for something named *php*

    Then it's just a matter of running the interpreter with the script as the
    first argument. e.g.

    php /home/virtual/blahblah.com/home/abc/mainwebsite_htm l/bluhbluh/dbtest/test.php

    although you may not want extraneous html in your output so....

    php -q test.php


    Just in case you can't find it, and can't install your own, you can fetch a
    web page from the comand line using a variety of tools - most boxes will
    have wget and/or curl.

    HTH

    C.

    Comment

    • merlinfly

      #3
      Re: How can I run php scripts from a shell script?

      you can also set the script up like a normal shell script in the form
      of...

      -- start file --
      #!/usr/local/bin/php -q
      <?

      /* php code here */

      ?>
      -- end file --

      the path to php can be take the form of

      /usr/local/bin/php
      /usr/bin/env php
      /usr/bin/which php

      etc.
      they should all work out fine.

      Good luck!

      Comment

      Working...