1

I want to play a video at a certain time. Like an alarm. for instance, at 07:00 play video.mp4

I have tried this with crontab and with at, but no success yet

0

I wrote a little script for that:

#!/bin/bash
[ "$1" = "-q" ] && shift && quiet=true || quiet=false
hms=(${1//:/ })
printf -v now '%(%s)T' -1
printf -v tzoff '%(%z)T\n' $now
tzoff=$((0${tzoff:0:1}(3600*${tzoff:1:2}+60*${tzoff:3:2})))
slp=$(((86400+(now-now%86400)+10#$hms*3600+10#${hms[1]}*60+${hms[2]}-tzoff-now)%86400))
$quiet || printf 'Alarm goes off at %(%c)T.' $((now+slp))
sleep $slp
mplayer /path/to/video.mp4

Call it with the desired time like alarm.bash 7, alarm.bash 7:1:3 or alarm.bash 07:01:03. You may use the -q option to disable the terminal output. Designed to serve as an alarm clock it's not possible to set a time more than 23:59:59 in the future with this script – I suggest to combine it with cron if necessary.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.