2

I have the following files:

vars.txt

C=1234567890

Ascript.php

#!/usr/bin/php
<?php
var $C="$argv[1]";
echo "\n $C \n";

$con = mysql_connect('localhost','root','123') or die ("No connected");
mysql_select_db("test_database",$con);

if($C !=''){
  $rs = mysql_query("SELECT name FROM test_table WHERE `identifier`= '$C'");
  while($fields = mysql_fetch_row($rs)){
    $file = fopen("/var/log/Test/Result.txt","a") or die ("No created");
    for ($i=0, $x=count($fields); $i < $x; $i++){
      fputs($file, "$fields[$i]\n");
      fclose($file);
    }
  }
}
else {
echo "There is not identifier \n";
}
mysql_close($con);
?>

Bscript.sh

#!/bin/bash
C=`grep -oPa '[Cc]=[^\s]+' /var/log/Test/vars.txt|cut -d= -f2|sed -e 's/-//'`
echo -e "Identifier: $C"
`php -f /root/Ascript.php $C`

When I execute from cli:

[me]# php -f Ascript.php 1234567890

There's no problem!

But if I execute:

[me]# ./Bscript.sh

(Bscript has 755 permissions) I get this:

Identifier: 1234567890
./Bscript.sh: line 4: 1234567890: command not found

Even if I write the value directly in my Bscript.sh

...
`php -f /root/Ascript.php 1234567890`

I get the same error.

2

The problem is the backticks around the line

php -f /root/Ascript.php $C

They mean to the shell: "Execute the command in between, collect its output (only that to stdout) and then replace the backticks and everything in between with the output.

As there is noting else on that line the output (1234567890) is considered a command. Just remove the backticks.

You can check with by prepending an echo:

echo `php -f /root/Ascript.php $C`
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.