Все сделал, все работает. Если кому интересно могу поделится скриптами.
PHP который генерирует инструкции. PRJ_DIR - константа путь к проекту.
Код: Выделить всё
$dir = $l_code;
$source = PRJ_DIR . 'ecms/orders/hold/' . $dir . '/';
$destination = PRJ_DIR . 'ecms/orders/transfer/' . $dir . '/';
$file_sh_convert = PRJ_DIR . 'ecms/orders.sh/convert/' . $dir . '.sh';
$file_sh_transfer = PRJ_DIR . 'ecms/orders.sh/transfer/' . $dir . '.sh';
$this->_make_dir($destination);
$directory = dir($source);
file_put_contents($file_sh_convert, '#!/bin/sh' . "\n\n");
while (false !== ($file = $directory->read())) {
if ($file == '.' || $file == '..') {
continue;
}
if ($file == 'order.txt') {
copy($source . $file, $destination . $file);
continue;
}
$source . '/' . $file;
$current = $path_convert . 'convert ' . $source . $file . ' -units PixelsPerInch -density 300x300 -sampling-factor 4:2:2 -quality 95 -strip ' . $destination . $file . "\n";
file_put_contents($file_sh_convert, $current, FILE_APPEND);
}
file_put_contents($file_sh_convert, 'mv ' . $destination . $dir . '.sh ' . $file_sh_transfer, FILE_APPEND);
chmod($file_sh_convert, 0777);
file_put_contents($destination . $dir . '.sh', '#!/bin/sh' . "\n\n" . 'mv ' . $destination . ' ' . str_replace('transfer/', 'print/.', $destination) . "\n" . 'mv ' . str_replace('transfer/', 'print/.', $destination) . ' ' . str_replace('transfer/', 'print/', $destination));
chmod($destination . $dir . '.sh', 0777);
$directory->close();
photobooks_conver.sh
Код: Выделить всё
#!/bin/sh
flagfile="/root/photobooks_conver_flag"
if [ -f ${flagfile} ];
then exit
fi
echo "photobooks_conver_flag" > ${flagfile}
dir= PRJ_DIR + "ecms/orders.sh/convert"
cd ${dir}
for i in $dir/*;
do
if [ -f $i ]
then $i && rm $i
fi
done
rm ${flagfile}
И аналогичный photobooks_transfer.sh
Код: Выделить всё
#!/bin/sh
flagfile="/root/photobooks_transfer_flag"
if [ -f ${flagfile} ];
then exit
fi
echo "photobooks_transfer_flag" > ${flagfile}
dir=PRJ_DIR + "ecms/orders.sh/transfer"
cd ${dir}
for i in $dir/*;
do
if [ -f $i ]
then $i && rm $i
fi
done
rm ${flagfile}
Оба запускаются по крону раз в 10 минут. Первый скрипт исполняет весь набор инструкция по конвертации, второй исполняет наборы инструкций по переносу. Не хватает наверное проверки срока жизни флага, возможен выход без удаления или сбой когда флаг не сотрется, проверить если старше скажем 12 часов, то убить принудительно.