#!/bin/sh
#
echo "################################################"
echo "# SMI to SRT convertor crontab ver 1.0          "
echo "# Created date: 2013.01.17                      "
echo "# Creator info: http://www.nkpark.pe.kr         "
echo "################################################"
targetdir=/volume2/video
workdir=/volume1/homes/root             
workfile=/volume1/homes/root/nksmi2srt.work                          
find ${targetdir} -name "*.smi" -exec ls {} \; > ${workfile}
                                
nkline=`cat ${workfile} | wc -l`
i=1  
iok=0
sok=0
eok=0                       
while [ ${i} -le ${nkline} ]
do               
    read filename                                                                             
    echo "[${i}]-----------------------------------------------------------------------------"
    echo "input: ${filename}"                                          
    ofilename=`dirname "${filename}"`/`basename "${filename}" .smi`.srt
    echo "ouput: ${ofilename}"
                            
    if [ -f "${ofilename}" ]
    then                    
       sok=`expr ${sok} + 1`
       echo "--> Skip....."
    else                                                            
       ${workdir}/nksmi2srt.sh "${filename}" "${ofilename}"         
       if [ -f "${ofilename}" ]
       then                    
          iok=`expr ${iok} + 1`           
          echo "--> Change Completed!!!!!"
       else                    
          eok=`expr ${eok} + 1`       
          echo "--> Change Error....."
       fi
    fi               
    i=`expr ${i} + 1`
done < ${workfile}
i=`expr ${i} - 1`                                                                        
echo "----------------------------------------------------------------------------------"
echo "## Total: ${i}, Skip: ${sok}, Changed: ${iok}, Error: ${eok}"