An ugly bash script :(

Mark a record auto-upload script.

#!/bin/bash
dir="/home/Record/Save"

while :
do
    for file in ${dir}/*.flv
    do
        if [[ -f "${file}" ]]; then
            isOpen=`lsof "${file}"`

            if [[ -z "${isOpen}" ]]; then
                echo "${file}" is not open
                if [[ -z $(BaiduPCS-Go ls /Record/`date -d "6 hour ago" +"%Y-%m-%d"`/ | grep "文件或目录不存在") ]]; then
                    if [[ $(find "${file}" -type f -size +102400c 2>/dev/null) ]]; then
                        /usr/bin/ffmpeg -i "${file}" -vcodec copy -acodec copy "${file%.flv}.mp4" && rm -rf "${file}"
                        /usr/bin/BaiduPCS-Go u --nofix "${file%.flv}.mp4" /Record/`date -d "6 hour ago" +"%Y-%m-%d"`/ && rm -rf "${file%.flv}.mp4"
                    else
                        echo Delete trash file "${file}".
                        rm -rf "${file}"
                    fi
                else
                    /usr/bin/BaiduPCS-Go mkdir /Record/`date -d "6 hour ago" +"%Y-%m-%d"`
                fi
            fi
        fi
    done
    sleep 10
done
Last modification:October 20th, 2019 at 06:33 am
If you think my article is useful to you, please feel free to appreciate

Leave a Comment