Skip to content

Instantly share code, notes, and snippets.

@ryosan-470
Created March 23, 2014 01:00
Show Gist options
  • Save ryosan-470/9716831 to your computer and use it in GitHub Desktop.
Save ryosan-470/9716831 to your computer and use it in GitHub Desktop.
epgrecを自動起動, 自動終了スクリプト. 参考:http://d.hatena.ne.jp/ftem/20120315/1331817148
#!/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
@ryosan-470
Copy link
Author

概要

epgrecの録画前に自動起動し終了後自動的にシャットダウンする.cronに登録しておく.追加機能としてrecpt1でのhttpリアルタイム放送を行っているときはシャットダウンしないようにしている.

動作確認環境: Ubuntu 12.04.4 LTS

参考

http://d.hatena.ne.jp/ftem/20120315/1331817148

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment