なんとな~くしあわせ?の日記

JavaとかAWSの設定とかをメモする技術ブログ

シェルスクリプトでふしぎの海のナディアを予約する

#!/bin/bash

# for (( 初期設定;条件;更新処理 ))
for (( LOOP=4 ; LOOP < 40 ; LOOP++ ))
do

   # 取得する日付を計算する
   week_to_add=`expr ${LOOP} - 4`

   ID_EpisodeNum="372-${LOOP}-"
   recdate=`date +"%Y%m%d" --date "${week_to_add} week"`
   rectime="-1755.m2t"
   videoname=${ID_EpisodeNum}${recdate}${rectime}

   # atコマンドに入れる命令を作成する
   command="recpt1 --b25 --strip 13 1800 /home2/videodir/"
   order=${command}${videoname}

   # DD/MM/YY形式の録画日時を出す
   rectime_at=`date +"%m/%d/%Y" --date "${week_to_add} week"`

   # atコマンドで予約
   echo \"${order}\" |at 17:55 ${rectime_at}
done

# sample
# recpt1 --b25 --strip 13 1800 /home2/videodir/372-3-20120421-1755.m2t


出力結果

4202    Sat Jun 16 17:55:00 2012 a root
4211    Sat Aug 18 17:55:00 2012 a root
4173    Sun Apr 29 17:25:00 2012 a foltia
4223    Sat Nov 10 17:55:00 2012 a root
4206    Sat Jul 14 17:55:00 2012 a root
4200    Sat Jun  2 17:55:00 2012 a root
4219    Sat Oct 13 17:55:00 2012 a root
4212    Sat Aug 25 17:55:00 2012 a root
4208    Sat Jul 28 17:55:00 2012 a root
4229    Sat Dec 22 17:55:00 2012 a root
4204    Sat Jun 30 17:55:00 2012 a root
4213    Sat Sep  1 17:55:00 2012 a root
4198    Sat May 19 17:55:00 2012 a root
4199    Sat May 26 17:55:00 2012 a root
4203    Sat Jun 23 17:55:00 2012 a root
4226    Sat Dec  1 17:55:00 2012 a root
4216    Sat Sep 22 17:55:00 2012 a root
4209    Sat Aug  4 17:55:00 2012 a root
4174    Sun Apr 29 02:15:00 2012 a foltia
4207    Sat Jul 21 17:55:00 2012 a root
4220    Sat Oct 20 17:55:00 2012 a root
4221    Sat Oct 27 17:55:00 2012 a root
4230    Sat Dec 29 17:55:00 2012 a root
4227    Sat Dec  8 17:55:00 2012 a root
4210    Sat Aug 11 17:55:00 2012 a root
4215    Sat Sep 15 17:55:00 2012 a root
4224    Sat Nov 17 17:55:00 2012 a root
4225    Sat Nov 24 17:55:00 2012 a root
4218    Sat Oct  6 17:55:00 2012 a root
4217    Sat Sep 29 17:55:00 2012 a root
4201    Sat Jun  9 17:55:00 2012 a root
4222    Sat Nov  3 17:55:00 2012 a root
4172    Sun Apr 29 08:25:00 2012 a foltia
4214    Sat Sep  8 17:55:00 2012 a root
4175    Sun Apr 29 01:45:00 2012 a foltia
4205    Sat Jul  7 17:55:00 2012 a root
4197    Sat May 12 17:55:00 2012 a root
4196    Sat May  5 17:55:00 2012 a root

改良版

上のスクリプトでは実際に録画ができなかったので、シェルスクリプト指定してみる

#!/bin/bash

for (( LOOP=10 ; LOOP < 40 ; LOOP++ ))

do
   # 取得する日付を計算する
   week_to_add=`expr ${LOOP} - 10`

   ID_EpisodeNum="372-${LOOP}-"
   recdate=`date +"%Y%m%d" --date "${week_to_add} week"`
   rectime="-1755.m2t"
   videoname=${ID_EpisodeNum}${recdate}${rectime}

   # シェルスクリプト用ファイルを出力する
   command="recpt1 --b25 --strip 13 1800 /home2/videodir/"
   order=${command}${videoname}

   # 録画スクリプトの名前
   scriptname=nadia_script_#${LOOP}.sh

   `echo "#!/bin/bash" >./${scriptname}`
   `echo >>./${scriptname}`
   `echo ${order} >>./${scriptname}`

   # DD/MM/YY形式の録画日時を出す
   rectime_at=`date +"%m/%d/%Y" --date "${week_to_add} week"`

   # atコマンドで予約
   at -f ./${scriptname} 17:55 ${rectime_at}
done