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


I wrote a little script for that:

[ "$1" = "-q" ] && shift && quiet=true || quiet=false
hms=(${1//:/ })
printf -v now '%(%s)T' -1
printf -v tzoff '%(%z)T\n' $now
$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.