Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

patiobar with cron #32

Open
K37V1N opened this issue Jul 23, 2021 · 4 comments
Open

patiobar with cron #32

K37V1N opened this issue Jul 23, 2021 · 4 comments

Comments

@K37V1N
Copy link

K37V1N commented Jul 23, 2021

I'm trying to run patiobar/pianobar with crontab but I can't seem to get the audio to actually work. The only error message in a log I've gotten is something like "can't start audio device". Any suggestions for how to run this with Cron?

@Cloud9Developer
Copy link

Cloud9Developer commented Jul 23, 2021

From a quick Google search, there's an env variable that needs to be set (which isn't set when cron jobs run). I am not too familiar with getting sound working with cron, so I can't give any more info than that to help.

However, a workaround is to do something similar to what I do. I have a service that detects when my phone is connected to the network. If it's been an hour or more since the last connection, it'll trigger patiobar to start

@kylejohnson
Copy link
Owner

@K37V1N Yeah, I'd say this is almost certainly an env var issue, as @cph015 mentioned.
Is this in your own crontab (crontab -e), or root's crontab, or some other user?
If it is your own user, you should already be in the audio group.

From what I'm reading, you'll need to get the XDG_RUNTIME_DIR env var from your current session:

env|grep -i runt
XDG_RUNTIME_DIR=/run/user/1000

And then set that in your crontab, something like: * 1 2 3 4 5 XDG_RUNTIME_DIR=/run/user/1000 /path/to/what/you/are/starting.sh

But let me ask, why are you running Patiobar in cron? I'm curious about your usecase.

@K37V1N
Copy link
Author

K37V1N commented Jul 29, 2021

I'm doing this on a raspberry pi, and using Raspbian for the OS. I'm editing the cron with crontab -e, so I believe it's running with the default user of "Pi".

User case is running music for animals in a shelter/adoption environment. I'm wanting to be able to turn on music at say 11am which is after the feeding and walking in the morning, and before the adoption floor is open. We've setup an hour long nap time for them, so I'd like some calm classical music type stuff to play during that time and for it to automatically start playing without anyone having to do anything. I'd also like it to be able to stop at the end of the day so the music isn't playing the entire night. Our behaviorists have talked about calming music possibly being a calming influence on the dogs behavior and I'm curious if it will be. I'm also curious if the music starts at the exact same time everyday (the same time the lights turn off/dim) if that will help trigger the dogs to take a nap.

I'll give the XDG_RUNTIME_DIR a test and see what I can get to happen. Just for clarification, what is the "=/run/user/1000" part of that command?

@kylejohnson
Copy link
Owner

That is a very noble cause! Sounds like a good use case for running this via cron.

  1. env | grep -i runt: If you run env, it lists all of your current environment variables. | grep -i runt pipes the output of env in to grep, and searches for a case-insensitive (-i) match for runt. runt matches XDG_RUNTIME_DIR. Doing env | grep XDG_RUNTIME_DIR would give you the same result.
  2. XDG_RUNTIME_DIR=/run/user/1000: This is the output from the env | grep -i runt command. In this case, XDG_RUNTIME_DIR is the name of the variable, and /run/user/1000 is the value assigned to that variable.

Here's an example where I'm searching for the PWD, which returns two variables, and then for OLDPWD, which only returns one. The env | wc -l line shows that there are 50 environment variables in my current session.

kjohnson@Kyles-MacBook-Pro ~ % env | wc -l
      50
kjohnson@Kyles-MacBook-Pro ~ % env | grep PWD
PWD=/Users/kjohnson
OLDPWD=/Users/kjohnson/Patiobar
kjohnson@Kyles-MacBook-Pro ~ % env | grep OLDPWD
OLDPWD=/Users/kjohnson/Patiobar
kjohnson@Kyles-MacBook-Pro ~ % 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants