0

I would like to use crontab in Bash on a Raspberry Pi to open a mp4 video at certain times. I am very much a newby can anybody give me any advice or direct me where to dig further.

I had previously posted this message on the Rpi forum but was advised to post it here.

Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
Harold
  • 1
  • 1
  • It should be the exact same as a desktop linux system. – Philip Kirkbride Jan 26 '17 at 18:17
  • 1
    Possibly relevant [Using notify-send with cron](http://unix.stackexchange.com/questions/111188/using-notify-send-with-cron) – roaima Jan 26 '17 at 21:14
  • Possibly relevant [How can I use cron to display messages on the screen via notify-send](http://unix.stackexchange.com/questions/20346/how-can-i-use-cron-to-display-messages-on-the-screen-via-notify-send?rq=1) – roaima Jan 26 '17 at 21:15

2 Answers2

1
  1. Running under user account, use crontab -e to edit your user's crontab

    crontab -e

  2. Create a new entry in the crontab file:


| | | | | | 
| | | | | +-- Year              (range: 1900-3000)
| | | | +---- Day of the Week   (range: 1-7, 1 standing for Monday)
| | | +------ Month of the Year (range: 1-12)
| | +-------- Day of the Month  (range: 1-31)
| +---------- Hour              (range: 0-23)
+------------ Minute            (range: 0-59)
  1. The template above represents the fields you can enter into the crontab file. Think of each field as an entry followed by a space to separate fields.

For instance,

00 1 * * 1 * echo "hello!" >> ~/hello

would execute the command 'echo "hello!" >> ~/hello' every Monday at 1:00AM.

An asterisk represents an unused field, equivalent to N/A.

Make sure whatever command you're using has permission to modify the files/folders you want to modify.

  1. Save the crontab file after you're done editing and it will run at the next instance.
Patrick
  • 589
  • 3
  • 20
  • While this information is correct it won't help the user "_open a mp4 video at certain times_". – roaima Jan 26 '17 at 21:12
  • That would be entirely dependent on what command the user is using. Since they didn't specify, I gave them the tools to add that command in. – Patrick Jan 27 '17 at 17:17
  • No, the point is that no matter what command they add, it won't work from `crontab` without the user jumping through hoops. Take a look at my "possibly relevant" links on the OP's question itself. – roaima Jan 27 '17 at 17:43
  • The ease of use of the tool is entirely opinion-based. While there might be an easier way to do this, using at or some other method, the user specifically mentioned using a crontab, so I gave them the instructions to do so. I understand your point, but your initial comment that it "won't help" is subjective. – Patrick Jan 27 '17 at 22:43
  • I guess that my question was too broad. But before I got down into the details my first question was "Will crontab be functional with Bash". I understand that Bash is a subset of Unix but does it include the required features to be able to use the command on a Raspberry Pi computer. – Harold Jan 30 '17 at 11:36
  • Crontab is functional on a Linux System. Bash is also functional on a Linux system. They are not really "functional" with each other because they are separate programs. Bash is a shell that you use to interact with your system. Crontab is a file that is edited by the user and then executed by the cron program. Both Bash and Cron run on most Linux distributions that work on the Raspberry Pi. Bash and Cron are both very "standard" programs that are included in most flavors of Linux. Does that help explain the difference? – Patrick Jan 31 '17 at 03:36
0

You could use omxplayer for that, run crontab -e, (choose an editor if you haven't already), go to the bottom of the file and add:

32 15 * * * omxplayer -o hdmi /path/to/video.mp4

Where 32 = minute and 15 = hour. Note that you may need to export DISPLAY=:0 before.

Ciprian
  • 101
  • 1