[SOLVED] Passing variable from bash script to php script.
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am at my wits end on this one. What syntax error?
Quote:
dave@Dafydd:~/PlayingWhere$ ./build_search_data.sh 01/23/2013
./build_search_data.sh: line 2: ?php5: No such file or directory
./build_search_data.sh: line 5: syntax error near unexpected token `" {$_SERVER['argv'][1]}"'
./build_search_data.sh: line 5: ` $searchPattern=(" {$_SERVER['argv'][1]}");'
dave@Dafydd:~/PlayingWhere$
I want to pass a data string from a bash script to a php script. I have an application my computer that uses a line simular to line 5 that recieves an email address and send out the email. I've read through w3schools, php.org, phpfreaks and a bunch of google finds, but nothing seems to work.
Can someone tell me what I am doing wrong?
Thanks for any light you can shed on this.
Dave
Code:
#!/bin/bash
<?php5
function lookfor.php()
{
$searchPattern=(" {$_SERVER['argv'][1]}");
$file = fopen("WhereAmIPlaying", "r") or exit("Unable to open file!");
while(!feof($file))
{
$stringToSearch = fgets($file);
$locationOfString = stripos($stringToSearch , $searchPattern);
if("$locationOfString" !== false)
{
printf('%s', "$stringToSearch");
}
}
fclose($file);
}
?>
## Build search string
day=$1
main ()
{
cat out.txt | (
while read city_to_find;
do build_search_string "$day" "$city_to_find";
done
)
}
php_EXEC='php5 -r'
function build_search_string()
{
giglocation=$2
I_want_to_attend="$day"",""$giglocation"
## confirm the data it correct and there
## echo "$I_want_to_attend";
php5 -f lookfor.php5 "$I_want_to_attend";
}
main
You are using the wrong shebang! (The first line of a file starting with #!. It tells the calling program which program it should use to interpret the script.
So you can either remove the shebang line and call the script with php -e /path/to/file or put the path to the php binary in place of /bin/bash in the first line.
There also I a little trick and put #!$(which php) as first line. This calls which which returns the path to the binary past as the first argument to it.
I got the syntax error gone. Thank you 'NevemTeve'.
Some printf statements show that the correct data is being passed. But it is not returning any results.
does not work?
Is there a different PHP search I could use?
Quote:
$searchPattern will have this format: 11/02/2013,Galveston, TX
WhereAmIPlaying will have this format: 11/02/2013,Galveston, TX,Jana Pochop,artistwebsite.html,venuewebsite.html
Code:
#!/usr/local/bin/php
<?php
$file = fopen("WhereAmIPlaying", "r") or exit("Unable to open file!");
while(!feof($file))
{
for ($i=1; $i<$argc; ++$i) {
$searchPattern = $argv[$i];
$stringToSearch = fgets($file);
$locationOfString = stripos($stringToSearch, $searchPattern);
if($locationOfString !== false)
{
printf('%s', $stringToSearch);
}
}
}
fclose($file);
?>
Want to thank you guys for the feed back. The problem I was having was my own goof up. My code was searching one part of the state for an event. My data base was for a different part of the state. Once that was fix, everything works as expected. Mark this solved.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.