シェルスクリプトのファイルアップロードCGIでThe timeout specified has expired:など

tail /var/log/apache2/error.log

[cgid:error] [pid 21449:tid 2956936192] (32)Broken pipe: [client 192.168.11.83:49924] AH02651: Error writing request body to script /www/remote-hand/sound_upload.cgi, referer: http://iot001/remote-hand/pi_int.html?1666515683894
[core:error] [pid 21449:tid 2956936192] (104)Connection reset by peer: [client 192.168.11.83:49924] AH00574: ap_content_length_filter: apr_bucket_read() failed, referer: http://iot001/remote-hand/pi_int.html?1666515683894
[cgid:error] [pid 21449:tid 2998899712] (70007)The timeout specified has expired: [client 192.168.11.90:43102] AH01270: Error reading request entity data,

シェルスクリプトでファイルアップロードがうまくいかないエラーに悩まされる

cat sound_upload.cgi
#!/bin/bash

<META http-equiv=”Refresh” content=”2;URL=/remote-hand/wait_for.cgi”>

cat >$tSOUND_FILE
cat $tSOUND_FILE | sed -n 6,6p|awk ‘{gsub(“\r”,””,$0);gsub(“;”,””,$0);printf(“%s\n%s\n”,$3,$4)}’ >$tFILE_NAME
. $tFILE_NAME
SIZE=`cat $tSOUND_FILE | awk ‘NR == 4{gsub(“\r”,””,$0);printf $1}’`
case $name in
“sound_file_0”)
tmp=”sound_file[0]”
n=0
;;

分かってみれば簡単な事かもしれないがcgiの許容時間が2秒と短過ぎcatでSTDIN読みきれずにリセットされる?

それとffmpegでファイル変換に時間がかかり過ぎた

なので2秒→30秒、LOCK機構と空読み、ファイル変換をバックグランド処理で行うように

<META http-equiv=”Refresh” content=”30;URL=/remote-hand/wait_for.cgi”>

if [ -e $tSOUND_FILE ];then
cat >$ttSOUND_FILE
rm $ttSOUND_FILE
echo -en ‘
</HTML>’
exit
fi

cat >$tSOUND_FILE
cat $tSOUND_FILE | sed -n 6,6p|awk ‘{gsub(“\r”,””,$0);gsub(“;”,””,$0);printf(“%s\n%s\n”,$3,$4)}’ >$tFILE_NAME
. $tFILE_NAME
SIZE=`cat $tSOUND_FILE | awk ‘NR == 4{gsub(“\r”,””,$0);printf $1}’`
case $name in
“sound_file_0”)
tmp=”sound_file[0]”
n=0
;;

https://github.com/kujiranodanna/IOT-House/blob/master/raspberrypi/www/remote-hand/sound_upload.cgi

Follow me!