captr
Posts: 3
Joined: Fri May 25, 2018 1:22 pm

Script doesn't run in crontab, but runs in command line

Fri Jan 18, 2019 10:05 pm

Hi,
this script runs in commandline, but not in cron

Code: Select all

SHELL=/bin/sh
PATH=/bin:/sbin:/usr/bin:/usr/sbin

nvlc http://wdr-1live-live.icecast.wdr.de/wdr/1live/live/mp3/128/stream.mp3
Crontab

Code: Select all

@reboot   /home/pi/myscripts/startmusic.sh
I think there is a problem with PATH, because when i put

Code: Select all

@reboot    nvlc http://wdr-1live-live.icecast.wdr.de/wdr/1live/live/mp3/128/stream.mp3
in crontab it also doesn't start the stream.
What can i do here?

greets

tempest766
Posts: 105
Joined: Sun Jan 07, 2018 3:44 pm

Re: Script doesn't run in crontab, but runs in command line

Fri Jan 18, 2019 10:07 pm

why are you doing this in cron? Cron is not for running things on reboot. it is for running tasks on a regular periodic basis.

put it in /etc/rc.local instead.

Andyroo
Posts: 1086
Joined: Sat Jun 16, 2018 12:49 am
Location: Lincs U.K.

Re: Script doesn't run in crontab, but runs in command line

Fri Jan 18, 2019 10:26 pm

CRON is fine for reboots BUT you need to have the GUI up and running

The other things that may stop you are:

1) The file not being flagged as executable
2) The hash bang / shebang missing from the start of the file (#!/bin/bash in this case)

I would look at system.d way of starting things now for more control - it’s the ‘latest and greatest’ method :lol: :roll: :lol:
Need Pi spray - these things are breeding in my house...

User avatar
DougieLawson
Posts: 34562
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Script doesn't run in crontab, but runs in command line

Fri Jan 18, 2019 10:29 pm

If your program needs the GUI start it from the autostart file.

/home/pi/.config/lxsession/LXDE-pi/autostart (or wherever it is on your system)
Note: Having anything remotely humorous in your signature is completely banned on this forum.

Any DMs sent on Twitter will be answered next month.

This is a hippy & doctor free zone.

User avatar
thagrol
Posts: 1163
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Script doesn't run in crontab, but runs in command line

Fri Jan 18, 2019 10:36 pm

tempest766 wrote:
Fri Jan 18, 2019 10:07 pm
why are you doing this in cron? Cron is not for running things on reboot. it is for running tasks on a regular periodic basis.

put it in /etc/rc.local instead.
That's exactly the opposite of what you should do. Most linux distributions (including debian, which raspbian is forked from) have deprecated (i.e. removed or marked for removal) /etc/rc.local. And if cron didn't want to run things at reboot why does the "@reboot" tag exist? rc.local use can also cause more problems that it solves. if you get it wrong and something fails (or never returns) you'll see a boot error logged and anything after it in rc.local won't even get the chance to run. With cron, only the failed job fails and the failure won't be treated as a failure to boot.

Don't want to use cron for @reboot jobs? That's fine but don't use /etc/rc.local either. Use a systemd service. Or use rc.local but be prepared for it to break with a future OS upgrade.

That said, the likely cause is not the PATH but that cron is running the OP's script before the network is up so it exits with an error. Which is lost as cron will throw away all output.

Debugging this stuff is straight forward.

First, change your crontab entry to

Code: Select all

@reboot   /home/pi/myscripts/startmusic.sh >/home/pi/myscripts/startmusic.log 2>&1
Next, reboot.
You can then examine the contents of /home/pi/myscripts/startmusic.log for output and error messages.

Once you know the error, you're on the way to fixing it. If you're not sure what it means or how to go about fixing it, post the error log here.
Last edited by thagrol on Fri Jan 18, 2019 10:39 pm, edited 1 time in total.
Note to self: don't feed the trolls

If I've asked you a question, please answer it. I'm unlikely to be able to help without that information.

User avatar
thagrol
Posts: 1163
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Script doesn't run in crontab, but runs in command line

Fri Jan 18, 2019 10:39 pm

Andyroo wrote:
Fri Jan 18, 2019 10:26 pm
CRON is fine for reboots BUT you need to have the GUI up and running
Only if it's a gui programme and you're not sending it to a remote display.

Edit: cron is not dependent on a GUI desktop. the things you try to start it may be though.
Note to self: don't feed the trolls

If I've asked you a question, please answer it. I'm unlikely to be able to help without that information.

captr
Posts: 3
Joined: Fri May 25, 2018 1:22 pm

Re: Script doesn't run in crontab, but runs in command line

Sat Jan 19, 2019 3:04 pm

The error.log

Code: Select all

[01f4ec20] pulse audio output error: PulseAudio server connection failure: Verbindung verweigert
[01ddee70] core interface error: no suitable interface module
[01dca8f8] core libvlc error: interface "globalhotkeys,none" initialization failed
[01ddee70] dbus interface error: Failed to connect to the D-Bus session daemon: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
[01ddee70] core interface error: no suitable interface module
[01dca8f8] core libvlc error: interface "dbus,none" initialization failed
Error opening terminal: unknown.

User avatar
thagrol
Posts: 1163
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Script doesn't run in crontab, but runs in command line

Sat Jan 19, 2019 4:49 pm

captr wrote:
Sat Jan 19, 2019 3:04 pm
The error.log

Code: Select all

[01f4ec20] pulse audio output error: PulseAudio server connection failure: Verbindung verweigert
[01ddee70] core interface error: no suitable interface module
[01dca8f8] core libvlc error: interface "globalhotkeys,none" initialization failed
[01ddee70] dbus interface error: Failed to connect to the D-Bus session daemon: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
[01ddee70] core interface error: no suitable interface module
[01dca8f8] core libvlc error: interface "dbus,none" initialization failed
Error opening terminal: unknown.
Several possibilities there, not sure which one it's likely to be. Let's take them one at a time:
  • "01f4ec20] pulse audio output error: PulseAudio server connection failure: Verbindung verweigert" Is the pulseaudio server daemon running, does root have apropriate permissions to connect to it?
  • "01ddee70] core interface error: no suitable interface module": Not sure, could be a configuration issue
  • "[01dca8f8] core libvlc error: interface "globalhotkeys,none" initialization failed" Again, not sure but does libvlc need X windows?
  • "[01ddee70] dbus interface error: Failed to connect to the D-Bus session daemon: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11" Something needs access to an X server. Jobs started by cron won't know where to find it as $DISPLAY won't be set in their environment. It's also likely that an X server won't be running and even if it is may reject the connection if you try to set DISPLAY in your script.
  • "[01ddee70] core interface error: no suitable interface module": Again, dunno
  • "[01dca8f8] core libvlc error: interface "dbus,none" initialization failed" se above
  • "Error opening terminal: unknown." Jobs started by cron aren't attached to a terminal so can't get input from, or send output to one.
It looks like you're trying toi start a desktop (X11) app from cron. That ain't gonna work as there are timing and dependency issues that won't be met.

Remove or comment out your crontab entry and try DougieLawson's suggestion instead.
Note to self: don't feed the trolls

If I've asked you a question, please answer it. I'm unlikely to be able to help without that information.

Return to “Troubleshooting”