Created
March 23, 2014 01:00
-
-
Save ryosan-470/9716831 to your computer and use it in GitHub Desktop.
epgrecを自動起動, 自動終了スクリプト. 参考:http://d.hatena.ne.jp/ftem/20120315/1331817148
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# sort works well when LANG=C | |
LANG=C | |
# Nobody use recpt1 realtime broadcast | |
if [ `ps aux|grep recpt1|grep http|wc -l` -ne 1 ]; then | |
# if nobody logged in. | |
if [ `who|wc -l` -eq 0 ] ; then | |
# if nobody are using samba. | |
if [ `smbstatus -L|wc -l` -eq 2 ]; then | |
# if no at jobs are runnning. | |
if [ `atq|grep =|wc -l` -eq 0 ]; then | |
# get nearest time which at scheduled. | |
nearest=`atq|awk '{print $6,$3,$4,$5}'|\ | |
sort -n -k 4|sort -k 1 -Mk 2 -k 3|\ | |
sort -n -k 3|head -1|awk '{print $2,$3,$4,$1}'` | |
# transform timestamp to seconds. | |
wkuptime=`date -d "$nearest" +%s` | |
# set secs to 3 minutes before. | |
wkuptime=`expr $wkuptime - 180` | |
# get present time. | |
now=`date +%s` | |
# if next recording will start after greater than 30 minutes later. | |
if [ `expr $wkuptime - $now` -gt 1800 ]; then | |
# initialize wakealarm. | |
echo 0 > /sys/class/rtc/rtc0/wakealarm | |
# set wakealarm. | |
echo $wkuptime > /sys/class/rtc/rtc0/wakealarm | |
# shutdown | |
/sbin/shutdown -h now | |
fi | |
fi | |
fi | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
概要
epgrecの録画前に自動起動し終了後自動的にシャットダウンする.cronに登録しておく.追加機能としてrecpt1でのhttpリアルタイム放送を行っているときはシャットダウンしないようにしている.
動作確認環境: Ubuntu 12.04.4 LTS
参考
http://d.hatena.ne.jp/ftem/20120315/1331817148