NOTE: This is an old article. Please go to the Meshlium development section in order to get the latest tutorials.

Call a PHP script from bash

Requeriments:

  • At least one Meshlium

Sometimes people have asked us about the possibility of call PHP scripts within a shell script. This how to will show some tricks to do that.


First we need to have a PHP script accesible from a web navigator. For this examples we will assume that a folder named my_php_scripts is under /var/www.



Trick 1: Just call a script and forget about it's output
	#!/bin/bash
	wget -q http://localhost/my_php_scripts/script_1.php -O /dev/null


Trick 2: Call a script and save it's output in /tmp/output
	#!/bin/bash
	wget -q http://localhost/my_php_scripts/script_1.php -O /tmp/output

Trick 3: Call a script and store it's output in a variable
	#!/bin/bash
	VAR=$(wget -q -O - http://localhost/my_php_scripts/script_1.php)
	echo $VAR


© Libelium Comunicaciones Distribuidas S.L.

| Terms of use