Reputation: 73
I'm not familiar with Linux and it's my first time using a Raspberry Pi. I am trying to set it to play an Mp3 file every day and came across using Crontab as a viable option. However I'm not sure how to save the files in the correct location because every time I write a script using crontab I can't seem to save it to a viable location...even writing a new crontab to the desktop won't work. Is there a more viable folder for putting all my crontabs? Again I'm new to the system so anything would help,
Thank you for taking the time to read this message.
Upvotes: 1
Views: 1008
Reputation: 73251
You can simply type
crontab -e
in the command line and add the file you want to run in one of the lines. Here's a short overview on how to write a cronjob:
Your cron:
30 20 * * 1-5 omxplayer /home/pi/desktop/wakeupsong.mp3
How to setup a cronjob in general:
# * * * * * command to execute
# │ │ │ │ │
# │ │ │ │ │
# │ │ │ │ └───── day of week (0 - 6) (0 to 6 are Sunday to Saturday, or use names; 7 is Sunday, the same as 0)
# │ │ │ └────────── month (1 - 12)
# │ │ └─────────────── day of month (1 - 31)
# │ └──────────────────── hour (0 - 23)
# └───────────────────────── min (0 - 59)
Special Characters in cron:
Asterisk (*)
The asterisk indicates that the cron expression matches for all values of the field. E.g., using an asterisk in the 4th field (month) indicates every month.
Slash ( / )
Slashes describe increments of ranges. For example 3-59/15 in the 1st field (minutes) indicate the third minute of the hour and every 15 minutes thereafter. The form "*/..." is equivalent to the form "first-last/...", that is, an increment over the largest possible range of the field.
Comma ( , )
Commas are used to separate items of a list. For example, using "MON,WED,FRI" in the 5th field (day of week) means Mondays, Wednesdays and Fridays.
Hyphen ( - )
Hyphens define ranges. For example, 2000-2010 indicates every year between 2000 and 2010 AD, inclusive.
Percent ( % )
Percent-signs (%) in the command, unless escaped with backslash (), are changed into newline characters, and all data after the first % are sent to the command as standard input.
Upvotes: 4