红联Linux门户
Linux帮助

shell 脚本 求注释

发布时间:2013-08-09 23:31:36来源:红联作者:jeenful
#!/bin/bash

video_path="/var/spool/asterisk/monitor/merge/"

store_tmp_path="/var/www/voices/"

#voices_error_path=${store_tmp_path}/error
voices_error_path="/var/www/voices_error/"

[ -d ${store_tmp_path} ] || mkdir -p ${store_tmp_path}

[ -d ${voices_error_path} ] || mkdir -p ${voices_error_path}


while :
do
cd $video_path

file_num=`ls ${video_path}| grep ".wav$" | wc -l`

if [ $file_num -lt 1 ] ; then
sleep 1
continue
fi

for file in `ls ${video_path} | grep ".wav$" `

do

if ( ! lsof ${video_path}/${file} > /dev/null 2>&1 )

then

/usr/local/bin/lame ${video_path}/${file} ${store_tmp_path}${file%.wav}.mp3

if [[ $? -eq 0 ]]

then

rm ${video_path}/${file}

else

mv ${video_path}/${file} ${voices_error_path}/

fi



fi
done

sleep 1
done
文章评论

共有 4 条评论

  1. Moffy 于 2013-09-24 22:20:54发表:

    学习ing~~~~~~~

  2. nic疯锋 于 2013-09-24 15:44:58发表:

    顶一个、

  3. Oersted 于 2013-08-11 08:54:49发表:

    帮顶下

  4. micy1985 于 2013-08-10 20:45:08发表:

    #!/bin/bash

    video_path="/var/spool/asterisk/monitor/merge/"

    store_tmp_path="/var/www/voices/"

    #voices_error_path=${store_tmp_path}/error
    voices_error_path="/var/www/voices_error/"

    [ -d ${store_tmp_path} ] || mkdir -p ${store_tmp_path}

    [ -d ${voices_error_path} ] || mkdir -p ${voices_error_path}


    while : #此处不需要":",为无限循环
    do
    cd $video_path

    file_num=`ls ${video_path}| grep ".wav$" | wc -l` #目录内以.wav结尾的文件个数

    if [ $file_num -lt 1 ] ; then #无wav文件则等待1秒返回“while”处继续
    sleep 1
    continue
    fi

    for file in `ls ${video_path} | grep ".wav$" ` #逐个对wav文件执行下列操作

    do

    if ( ! lsof ${video_path}/${file} > /dev/null 2>&1 ) #若无其他进程使用此文件

    then

    /usr/local/bin/lame ${video_path}/${file} ${store_tmp_path}${file%.wav}.mp3 #将wav转码为mp3,并保存到临时目录

    if [[ $? -eq 0 ]] #转码成功

    then

    rm ${video_path}/${file}

    else

    mv ${video_path}/${file} ${voices_error_path}/

    fi



    fi
    done

    sleep 1
    done