`
hyl198611
  • 浏览: 225695 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

shell学习(1)

阅读更多
脚本-1 findFile
configPath=$1
configContent=(`cat $configPath`)
cfiglen=${#configContent[@]}
path=$2
remoteCodePath=$3
cd $path
fileArray=(`ls | cut -d "." -f1`)
len=${#fileArray[@]}
index=0
for ((i=0;i<$len;i=i+1))
do
    if(($index == $cfiglen));
    then
        index=0;
    fi   

    if(($index != $cfiglen));
    then
        ssh root@${configContent[index]} /lekan/shell/transcode ${fileArray[i]} $remoteCodePath
        echo ${configContent[index]}  "------" ${fileArray[i]}
        index=$(($index+1))
    fi
done
---------------------------------------
脚本-2 transcode
fileName=$1
codePath=$2
if [ $fileName != "" ]; then
cd $codePath

videoId=`source ./fileRule getVideoId $fileName`
type=`source ./fileRule getType $fileName`
echo "fileName="$fileName",type="$type",videoId="$videoId


filePath="/lekan/"
ssmPath=$filePath`source ./fileRule getVideoPath $fileName`video.ssm/
mp4Path=$filePath`source ./fileRule getVideoPath $fileName`
imagePath=$filePath`source ./fileRule getImagePath $fileName`
echo "ssmPath="$ssmPath
echo "mp4Path="$mp4Path
echo "imagePath="$imagePath

urlPath="http://192.168.0.48:9001/transcode.jsp"
sta=`curl --data "operate=1&fileName=$fileName" $urlPath`
if [ "$sta" == "0" ]; then
echo $fileName "trancode error"
elif [ "$sta" == "1"  ]; then
echo "start transcode filename=$fileName"
if [ -d "$ssmPath" ];then
echo "ssmPath exist"
else
mkdir -p "$ssmPath"
fi
if [ -d "$imagePath" ]; then
echo "imagePath exist"
else
mkdir -p "$imagePath"
touch $imagePath"screenshot_data.xml"
source ./cxml $imagePath
fi
else
echo "unknown error"
fi
fi
---------------------------------------
脚本-3 fileRule
fileNamep=$2
function getType(){
if [ `expr index $fileNamep 'M'` \> 0 ]; then
echo 4
fi

if [ `expr index $fileNamep 'E'` \> 0 ]; then
echo 1
fi
}

function getVideoId(){
if [ `expr index $fileNamep 'M'` \> 0 ]; then
strMIdx=`expr index $fileNamep 'M'`
strMIdx=`expr $strMIdx - 1`
videoId=`expr substr "$fileNamep" 1 $strMIdx`
echo $videoId
fi

if [ `expr index $fileNamep 'E'` \> 0 ]; then
strEIdx=`expr index $fileNamep 'E'`
strEIdx=`expr $strEIdx - 1`
videoId=`expr substr "$fileNamep" 1 $strEIdx`
echo $videoId
fi
}

function getVideoPath(){
videoId=`getVideoId`
echo `expr $videoId % 1000`/`expr $videoId % 100`/$fileNamep/
}

function getImagePath(){
videoId=`getVideoId`
imagePath=""
lenth=`expr length $videoId`
if [ $lenth -le 2 ]; then
imagePath=$videoId/shot/
echo $imagePath
else
idx=1
while [ $idx -le $lenth ]; do
if [ $idx -ge $lenth ]; then
idx=$lenth
fi
imagePath+=`expr substr "$videoId" $idx 2`/
idx=`expr $idx + 2`
done
imagePath+=shot/
echo $imagePath
fi
}

if [ "$1" == "getType" ]; then
getType
fi
if [ "$1" == "getVideoId" ]; then
getVideoId
fi
if [ "$1" == "getVideoPath" ]; then
getVideoPath
fi
if [ "$1" == "getImagePath" ]; then
getImagePath
fi

-------------------------------------------
脚本-4 cxml
path=$1
xmlfile=$path"screenshot_data.xml"
cd $path
echo > $xmlfile
if [ -f $xmlfile ]; then
echo -e "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<shot>\n<time>60</time>" > $xmlfile
imgList=(`ls *_84x46.jpg`)
len=${#imgList[@]}
for((i=0;i<$len;i=i+1))
do
echo -e  "<pic time=\"10\" file=\"shot/"${imgList[i]}"\"/>" >> $xmlfile
done

echo "</shot>" >> $xmlfile
echo "operate xml success xmlfile="$xmlfile
else
echo "operate xml error xmlfile="$xmlfile
fi
--------------------------------------------
echo "email conetnt" | mail -s "email subtitle"  toEmail
发送Email
--------------------------------------------
stat -c "%s" file 查看文件大小
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics