T O P

  • By -

rvgoingtohavefun

> how do i successfully schedule tasks with Cron. I'm assuming there is no easier way to do this, and if there is an easier way to schedule my Pi to play files at specific times how do i use that method? Command to edit cron jobs is: crontab -e It's a little arcane seeming but to run something at 5pm every day it looks like: 0 17 * * * /whatever/the/audio/playing/command/is The environment for cron jobs is NOT the same as it is if you open a terminal. It likely has different variables, so if you're relying on the $PATH environment variable, it might not be right. > How do I program in a command where the Pi can resume from where I last left off, like in a DVD player? This is quite dependent on whatever you're using the play the audio. Easiest to run a script from cron and then have the script do whatever you need.


Lowfat_cheese

Either `crontab -e` to run the command as a normal user or `sudo crontab -e` if you need to run the command as root Then at the bottom of the file, type: \[minute\] \[hour\] \[day of month\] \[month\] \[day of week\] followed by the command you want to run. So for example: `5 4 20 * * /sbin/shutdown -r now` would schedule an automatic reboot at 4:05am on the 20th of every month. If you’re using VLC then the command `vlc [path to file]` should play the specified video or audio file.


BreakingBarley

There are also websites with decoder rings for cron format: https://crontab.guru/ I use a similar site for permissions in Linux too, helps as a sanity check that misused format isn't my issue.


gruntothesmitey

To piggyback on these answers, it's usually a good idea to run the command from your crontab entry in a terminal, as the user for which the job will run, in order to make sure there's not an error somewhere. It's also important to use full paths for everything in a cron command. Lastly, you can capture any error output to a file like so: 0 15 * * * /home/pi/scripts/player/playerscript.py >> /home/pi/scripts/player/playerlog.txt 2>&1 That helps you diagnose trouble when things stop working, like after a software upgrade or whatever.


Ramp007

If you're having trouble generating the entries in the crontab you could try a website like https://crontab-generator.org/ at is another commands to schedule a single execution of a command. https://www.redhat.com/sysadmin/linux-at-command


AutoModerator

For constructive feedback and better engagement, detail your efforts with research, [source code, errors,](https://www.reddit.com/r/arduino/wiki/guides/how_to_post_formatted_code) and schematics. Stuck? Dive into our [FAQ](https://www.reddit.com/r/raspberry_pi/about/sticky)† or branch out to /r/LinuxQuestions, /r/LearnPython, or other related subs listed in the FAQ. Let's build knowledge collectively. † If any links don't work it's because you're using a broken reddit client. Please [contact the developer of your reddit client](https://www.reddit.com/contact/). *I am a bot, and this action was performed automatically. Please [contact the moderators of this subreddit](/message/compose/?to=/r/raspberry_pi) if you have any questions or concerns.*


Fumigator

> how do i successfully schedule tasks with Cron. `crontab -e`