You are not logged in.
Ive been working on a script that allows me to download streams from my dreambox since it doesnt have a hard drive in it.
Right now I have to start it when I need to download the stream and its getting annoying.
What I want is some sort of time-programming so that I can easily enter time and date and it will automaticly run the specific commands at that time, in this case download the stream. But since my knowledge of bash-scripting is very limited and I have no idea on how to even start I need help. I was thinking of crontab but I dont know how to implement it.
Current script, heavily stripped. Its crude but it works for me.
#!/bin/bash
showMenu () {
echo ""
echo "Ripper Menu"
echo "1) SVT1"
echo "2) TV4 Sport"
echo ""
echo "3) Quit"
echo ""
}
while [ 1 ]
do
showMenu
read CHOICE
case "$CHOICE" in
"1")
echo "### Changing channel ###"
wget -q http://192.168.6.10:80/web/zap?sRef=1:0:1:449:2D:A027:FFFF0000:0:0:0:
wait
rm zap*
echo "### Downloading stream ###"
wait
wget -b http://192.168.6.10:8001/1:0:1:449:2D:A027:FFFF0000:0:0:0: -O svt1-`eval date +%Y-%m-%d_%H.%M.%S`.ts
;;
"2")
echo "### Changing channel ###"
wget -q http://192.168.6.10:80/web/zap?sRef=1:0:1:3F7:1E:A027:FFFF0000:0:0:0
wait
rm zap*
echo "### Downloading stream ###"
wait
wget -b http://192.168.6.10:8001/1:0:1:3F7:1E:A027:FFFF0000:0:0:0 -O tv4sport-`eval date +%Y-%m-%d_%H.%M.%S`.ts
;;
"3")
rm wget-log*
wait
killall wget
wait
exit
;;
esac
done
EDIT: basicly I want to start the script, press 1 and then enter the time and date and then enter and the commands will start when its time.
Last edited by maz (2010-10-05 19:39:14)
Offline
I would still suggest you have a look at http://wiki.archlinux.org/index.php/Cron
<when> <what> - <when> is the cron-formatted time, <what> is your script:
01 * * * * /home/user/bin/i_love_cron.sh
Last edited by karol (2010-10-03 16:00:03)
Offline
I would still suggest you have a look at http://wiki.archlinux.org/index.php/Cron
<when> <what> - <when> is the cron-formatted time, <what> is your script:01 * * * * /home/user/bin/i_love_cron.sh
Thanks for your reply but I know how cron works however I dont know how to implement it in my script, thats the question. Might have been vague in my OP
Offline
An example (tvrec)
#!/bin/sh
#channels=R12-Tvp1,R11-Tvp2,R7-Tvp3,SR6-Tv4,SR8-Tvn,SR3-Tvn7,SR16-Tvn_Turbo,R6-Polsat,SR14-Polsat_Sport_Extra,SR11-Discovery
_start_rec_year=2010
_start_rec_month=10
_start_rec_day=3
_start_rec_hour=2
_start_rec_minute=24
_stop_rec_year=2010
_stop_rec_month=10
_stop_rec_day=3
_stop_rec_hour=4
_stop_rec_minute=30
while [ true ]
do
_curr_year=`date +%Y`
_curr_month=`date +%-m`
_curr_day=`date +%-d`
_curr_hour=`date +%k`
_curr_minute=`date +%-M`
if [ ${_curr_year} -ge ${_start_rec_year} ]; then
if [ ${_curr_month} -ge ${_start_rec_month} ]; then
if [ ${_curr_day} -ge ${_start_rec_day} ]; then
if [ ${_curr_hour} -ge ${_start_rec_hour} ]; then
if [ ${_curr_minute} -ge ${_start_rec_minute} ]; then
dtach -n /tmp/tv_rec.dtach mencoder -tv driver=v4l2:width=768:height=576 -tv \
channels=R12-Tvp1 tv:// -o tv.avi -oac pcm -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=10000 &
echo "start rec"
break
fi
fi
fi
fi
fi
sleep 10
done
sleep 5
_kill=`ps aux | grep mencoder | grep -v grep | awk '{print $2}'`
while [ true ]
do
_curr_year=`date +%Y`
_curr_month=`date +%-m`
_curr_day=`date +%-d`
_curr_hour=`date +%k`
_curr_minute=`date +%-M`
if [ ${_curr_year} -ge ${_stop_rec_year} ]; then
if [ ${_curr_month} -ge ${_stop_rec_month} ]; then
if [ ${_curr_day} -ge ${_stop_rec_day} ]; then
if [ ${_curr_hour} -ge ${_stop_rec_hour} ]; then
if [ ${_curr_minute} -ge ${_stop_rec_minute} ]; then
kill ${_kill}
echo "stop rec"
break
fi
fi
fi
fi
fi
sleep 10
done
sync
You have to modify it to your needs.
Offline
Oh lovely. Ill get right on it when im not on my netbook, thank you!
Offline
The "at" command might be what you are looking for:
http://www.computerhope.com/unix/uat.htm
Something like using read (storing time as variable) + echo "command" | at -v <time variable> should be straightforward to integrate in to your script.
You need to run the atd daemon for at to work.
Offline
The "at" command might be what you are looking for:
+ 1
I made some sort of a reminder wrapper script long ago which I use ever since. Although this is meant to be used interactively it schould be no big problem to adapt the the OP's needs.
#!/bin/bash
#
# Issue an alarm using at and xmessage
# Usage:
# AL [@] delay [message timeout]]
# where @ denotes absolute time
# If not absolute time:
# delay is in minutes
# timeout is in seconds
#
# Defaults to 5 minutes delay: "ALARM"
# Message defaults to "ALARM"
PREFIX="now + "
SUFFIX=" minutes"
DELAY=15
MSG='ALARM'
TO=60
if [ "$1" == "-h" ] || [ "$1" == "--help" ]
then
echo "AL - Issue an alarm"
echo " AL [delay (in minutes) [message [timeout (in seconds)]]]"
echo " or"
echo " AL @ time [message [timeout (in seconds)]]"
echo " defaults: delay=15 message=\"ALARM\" timeout=60"
exit
fi
if [ "$1" == "@" ]
then
PREFIX=""
SUFFIX=""
shift
fi
if [ "$1"x != "x" ]
then
DELAY=$1
if [ "$2"x != "x" ]
then
MSG="$2"
if [ "$3"x != "x" ]
then
TO=$3
fi
fi
fi
# Xdialog Version
echo "BELL;DISPLAY=:0 Xdialog --timeout $TO --msgbox "\"$MSG\"" 0 0" | at $PREFIX$DELAY$SUFFIX
# xmessage version
# echo "BELL;DISPLAY=:0 xmessage -button OK -default OK -timeout $TO ""$MSG""" | at $PREFIX$DELAY$SUFFIX
if [ "$PREFIX"x != "x" ]
then
echo "Alarm \""$MSG"\" in $PREFIX$DELAY$SUFFIX using timeout $TO seconds"
else
echo "Alarm \""$MSG"\" at $DELAY using timeout $TO seconds"
fi
To know or not to know ...
... the questions remain forever.
Offline
Thnx for the 'at' tip. Been improving the script but Ive found it difficult to make sub menus. Any ideas/examples?
Offline
So after lots of trial n error I finally have a working script. Its a mess but it works!
#!/bin/bash
PS3='$ '
DATE=`date +%Y-%m-%d_%H.%M.%S`
IFS=";"
OPTIONS="SVT1;TV4 Sport;Quit"
select opt in $OPTIONS; do
if [ "$opt" = "Quit" ]; then
exit
elif [ "$opt" = "SVT1" ]; then
echo -n "Name (text_text): "
read NAME
echo -n "Start (YYMMDDHHmm): "
read START
echo -n "Stop (YYMMDDHHmm): "
read STOP
echo "wget -q --spider http://192.168.6.10:80/web/zap?sRef=1:0:1:449:2D:A027:FFFF0000:0:0:0:" | at -t $START
echo "wget -o /dev/null -q -N -b http://192.168.6.10:8001/1:0:1:449:2D:A027:FFFF0000:0:0:0: -O $NAME.$DATE.ts" | at -t $START
echo "killall wget" | at -t $STOP
elif [ "$opt" = "TV4Sport" ]; then
echo hi
else
echo moron!
fi
done
Offline