My problem is I set an array value to the name of a server as follow:
$appserver[$i]=`grep $ip[2] /etc/hosts |awk '{print $2}'`;
Later I do a test to see if the server is up or not (using a wget). If the test fails I keep track of that server being down by creating a file with that name using touch:
$touch=`touch /home/steve/data/$appserver[$i];
The file gets created successfully. Later when I go to test whether or not the file exists it never evaluates to true.
if(file_exists('/home/steve/data/$appserver[$i])) {
I have tried several different things including creating a new variable for $appserver[$i] and testing against it, which also does not work:
I am running php 5.1.6 on RHEL 5.
Here is the full code:
$appserver[$i]=`grep $ip[2] /etc/hosts |awk '{print $2}'`;
echo "appserver[i] = $appserver[$i]\n";
$get=`wget $key->url 2> /dev/null`;
if(file_exists('/home/user/Start')) {
$color[$i]="green";
$rm=`rm -rf /home/user/Start`;
}
else {
$color[$i]="red";
if($hostname=="xxxxx" ) {
**if(file_exists('/home/user/data/$appserver[$i]))** {**
echo "do nothing appserver file exists\n";
$touch=`touch /home/steve/data/notmailed`;
}
else {
echo "No app file mailed alert\n";
$touch=`touch /home/user/data/$appserver[$i]`;
}
}
}
Thank you.
'$appserver[$i]' != "$appserver[$i]"