shell_exec apache rendering problem

General discussions related to php

Moderators: egami, macek, gesf

Post Reply
edefranco
New php-forum User
New php-forum User
Posts: 2
Joined: Tue Nov 26, 2019 3:48 pm

Wed Nov 27, 2019 8:03 am

Hi to all !
I have a php code that call a bash script where I read row by row the output of the bash command ls -l referred to a specific directory where are only file dot.wav and dot.mp3.
The bash script filter the .mp3 and for any file get the date, the hour and the file name and with these data create an array that is saved as string into a /tmp/<array name> where the php read it and assume it as php array used for create a page.

The problem is that if I execute the bash script in linux shell bash all working fine; also if I call the php page from the bash shell with the command php miofile.php all working fine, as I aspect, but if I load the php page with the browser (executed by apache), the data about the date is read in different way: in detail, the date of the files are stored (and read from bash shell) as 2018-08-05 but when it is the execute by apache it is is rendering as Aug 5 and this change the awk field read from bash script.

My locale in bash shell (locale -a) is it_IT.utf8, the php command date_default_timezone_get(); give me Europe/Rome.

In the php I call the bash script with shell_exec("/usr/local/bin/seg_leggi_file4 $entry"); where $entry is a parameter passed to bash script as directory name.

The bash script that create the array for php is:

mioArray='$L'$leone' = array('
/bin/ls -l "$dove""$leone"/subdir/*.mp3 | awk '{print $6" "$7" "$8}' | (
while IFS= read -r riga
do
data=`echo $riga | awk '{print $1}'`
mioArray=`echo "$mioArray""$virg""$data"`
mioArray=`echo "$mioArray""$virg"","`
ora=`echo $riga | awk '{print $2}'`
mioArray=`echo "$mioArray""$virg""$ora"`
mioArray=`echo "$mioArray""$virg"","`
nome=`echo $riga | awk '{print $3}' | awk -F"subdir/" '{print $2}'`
mioArray=`echo "$mioArray""$virg""$nome"`
mioArray=`echo "$mioArray""$virg"","`
done
mioArray=${mioArray::-1}
mioArray=`echo "$mioArray"");"`
echo $mioArray > /tmp/$leone


$leone is the parameter $entry.

The php version is 5.2.4 and the Apache is 2.2.8, all on a ubuntu server.

I suspect that there are some problem on localization but I don't know where to put my hands.

There are some people that have idea about this problem and can help me ?

Thank in advance,

Emilio
Trieste -IT
edefranco
New php-forum User
New php-forum User
Posts: 2
Joined: Tue Nov 26, 2019 3:48 pm

Wed Nov 27, 2019 10:51 am

The problem can be resolved modifying the row in bash script

/bin/ls -l "$dove""$leone"/INBOX/*.mp3 | awk '{print $6" "$7" "$8}' | (

as follows:

/bin/ls -l --time-style="long-iso" "$dove""$leone"/INBOX/*.mp3 | awk '{print $6" "$7" "$8}' | (

Emilio
Trieste-IT
Post Reply