Skip to content

Instantly share code, notes, and snippets.

@astail
Last active August 29, 2015 14:23
Show Gist options
  • Save astail/f598c93232d76399e870 to your computer and use it in GitHub Desktop.
Save astail/f598c93232d76399e870 to your computer and use it in GitHub Desktop.
#!/bin/sh
#メインPCに動画を送ってエンコードさせるスクリプト。
#video_dirに保存している.ts動画を全てエンコードする。
#メインPCがついていなかった場合、WOLで起動させる。
#エンコードした動画名はDBにinsertする。
#エンコードした動画はowncloudのディレクトリに移動させる。
#ssh i7でメインpcにsshできるようにしておく。
#DB設定などは最終行に記述。
mac_add=xx:xx:xx:xx:xx:xx
hostip=192.168.0.xx
video_dir=/hdd1/video
dest_dir=/hdd2/owncloud/hoge/files/video
wol() {
/sbin/ether-wake -i eth0 $mac_add
nodotti=0
while true
do
if ping -c 1 $hostip >> /dev/null; then
break
fi
if [ $nodotti -eq 5 ]; then
echo ping not
exit 0
fi
sleep 10s
nodotti=`expr $nodotti + 1`
echo $i:$hostip ping check now
done
echo ping ok
sleep 5s
}
hoge=(`ls $video_dir | grep \\\.ts$`)
i=`expr ${#hoge[@]}`
while [ $i != 0 ]; do
erio="insert"
i=`expr $i - 1`
name=${hoge[$i]}
db=(`MYSQL_PWD="encode" mysql -N -B -u encoder encode -e "select name from encode;"`)
x=`expr ${#db[@]}`
while [ $x != 0 ]; do
x=`expr $x - 1`
dbname=${db[$x]}
if [ "$name" == "$dbname" ]; then
echo $nameはエンコード済みです。
erio="notinsert"
break
fi
done
if [ "$erio" != "notinsert" ]; then
echo $nameをエンコードします。
wol
scp $video_dir/$name i7:/root/Encode/
ssh i7 "cd /root/Encode && sh tsmp4.sh $name"
namekaku=`echo $name | sed -e "s/\.ts$//g"`
scp i7:/root/Encode/$namekaku\.mp4 $dest_dir/
chown -R nginx:nginx $dest_dir
rmname=`echo $namekaku | sed -e "s/^.*GR\(.*\)_.*$/GR\1/"`
ssh i7 "rm -f /root/Encode/$rmname*"
MYSQL_PWD="encode" mysql -N -B -u encoder encode -e "insert into encode (name,date) values('$name',now());"
sleep 5s
fi
done
echo encode end
ssh i7 "shutdown -h now"
#CREATE USER encoder@localhost;
#SET PASSWORD FOR encoder@localhost = PASSWORD('encode');
#create database encode;
#use encode;
#CREATE TABLE encode (id int(11) NOT NULL AUTO_INCREMENT,name text NOT NULL,date datetime NOT NULL,PRIMARY KEY(id)) ENGINE=InnoDB DEFAULT CHARSET=utf8;
#GRANT SELECT,UPDATE,INSERT,DELETE ON `encode`.* TO 'encoder'@'localhost';
#FLUSH PRIVILEGES;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment