2

I am using Linux Mint 18.3 Cinnamon 64-bit (Version 3.6.6), and I can't get any audio from ANYTHING run via cron. That includes command-line audio file players, TTS apps like espeak or festival, etc. Nothing seems to work from cron.

I use reminders for things like getting my workouts in, and the type for that day… But since switching from my old, now quite dead Mac Mini to Linux Mint, those don't work anymore (they do work from a normal xterm command line). I never use relative paths in crontab for anything, so that's not it.

I've tried getting error messages by directing standard error into the standard out and sending that output to append to a log file… Nothing. Just an empty log file.

I put the commands that were in my crontab file into a script, and replaced them in crontab with a (fully-qualified) path/filename. Then I open the same log file via the script. Once again, it's opened, but nothing is appended to it, and still no sound.

Has anyone seen this issue before? Any suggestions on more ways to debug this or fix it?

2
  • (1) Are you logged in (on the console) when your cron job runs? (2) Have you tried looking at your environment (run env) in your xterm session and in the cron job and comparing them? Commented Aug 26, 2018 at 3:50
  • Pulseaudio or ALSA? (1) Pulseaudio will only work as the logged in user, not as root (from cron). (2) ALSA directly may not work if Pulseaudio is using all ALSA devices. (3) If the cron scripts don't run as root, they may need to be in a group able to access audio devices.
    – dirkt
    Commented Aug 26, 2018 at 6:50

3 Answers 3

0

I found this on Linux Mint Forums for exactly your Mint version 18.3. Not sure, what exactly is root cause here, but Anyways, just give it a try.

0. Look for correct configurations in PavuControl

Pulse Audio Volume Control Configuration

If everything looks good, then proceed to it.

1. Install latest kernel version. Reboot & try again for sound.

Use UpdateManager or this command on terminal.

apt install linux-image-4.4.0-53-generic linux-image-extra-4.4.0-53-generic linux-headers-4.4.0-53-generic linux-headers-4.4.0-53

or in any doubt, just follow this Community Tutorial

2. Chcek for Audio , Drivers & Sound :

Run this command and look for output. Note If any missing.

pactl set-sink-mute 0 0 ;  pactl list sinks ; lspci -v | grep -A7 -i "audio" ; lsmod

It should look like this :

Audio: Card-1 NVIDIA GK107 HDMI Audio Controller
driver: snd_hda_intel bus-ID: 01:00.1
Card-2 Advanced Micro Devices [AMD/ATI] SBx00 Azalia (Intel HDA)
driver: snd_hda_intel bus-ID: 00:14.2
Sound: Advanced Linux Sound Architecture v: k4.4.0-116-generic

If you see the Advanced Linux Sound Architecture, installing alsamixergui might help.

3. AlsaMixerGUI : Install - Run - Reboot - Test - Sound

  • Install alsamixer

    sudo apt-get install alsamixergui
    
  • Run it

    alsamixer
    
  • Press F6 and choose the one or the other of your sound cards and test if the sound works.

  • Sometimes force reloading alsa could help. To do that open a terminal and run :

    sudo alsa force-reload
    
  • Will take some seconds before it is done. Reboot your computer and see if you get any sound.

4. Reinstall Alsa and PulseAudio and Reboot

Remove all alsa-base and pulseaudio packages.

sudo apt-get remove --purge alsa-base pulseaudio

Clean install after update to get latest versions :

sudo apt-get update
sudo apt-get install alsa-base pulseaudio

Force reload Alsa

sudo alsa force-reload

Reboot.

5. Still not getting Sound :(

Well Atleast you tried. That's better. Feel free to add-in more details or any other solution that worked out for you.

7
  • Answer to 5 above: I am getting sound ... just not out of anything run by cron (all of which works fine when not run by cron).
    – GTbrewer
    Commented Jul 18, 2018 at 12:32
  • 1
    Or, put another way (btw, ~/bin/say is a shell script using festival and my options for it): This works: "$ say test" ... this does not: "* 16 * * * /home/jim/bin/say test" (from my crontab).
    – GTbrewer
    Commented Jul 18, 2018 at 12:42
  • @GTbrewer, How about writing an answer yourself that solves your OP ? Commented Jul 18, 2018 at 17:50
  • 1
    Don't I need to know why audio isn't working from cron before I can write that? Seems like that's something I'd need to know first. :-) Seriously, I've never run into a case where audio doesn't work when it's run from something in my crontab....I have no idea what could be causing this.
    – GTbrewer
    Commented Jul 18, 2018 at 22:45
  • 1
    Well, seems like this one has everyone stumped, so I'm changing directions, and am now writing a reminder service into a Tcl/Tk clock I wrote in the '90s. It will work similar to the calendar service crossed with cron ... checking ~/reminders every five minutes (not every minute like cron...but if you really need a reminder within five minutes, you're worse off than I am, having had three large brain tumors, three very severe brain surgeries to remove them, then whole-brain/max-dose radiation therapy.... Anyways, it will handle the reminders from that file. Thanks for trying!
    – GTbrewer
    Commented Jul 21, 2018 at 19:49
0

Ok, I don't have an answer for why it doesn't work but I do have a solution.

I discovered that sound is also broken for audible announcements via procmail for specific email senders.

So I created to VERY simple [Tcl][1] scripts. The first, run instead of espeak, etc., simply writes the text to a ~/.alerts file. The second sits in the background, a sort of daemon, waiting for that file to exist, and when it does, it reads and speaks every line in the file (usually only one) and then deletes the file. File locking is used in both scripts to avoid any collisions.

The Tcl script that checks ~/.alerts is run from an xterm, so it doesn't have whatever bug is messing with stuff from cron, procmail, and who knows what else. It just works.

So that's my solution. Like it, love it, hate it… it works for me.

The first script is addalert.

And this is the script---it just waits if the file is locked (max 20s then assume it's stuck) and writes the message from procmail:

#!/usr/local/bin/tclsh8.5

set lockfile /home/jim/.alertlock

proc checklock {} {
   global lockfile

   if {![file exists $lockfile]} { return }
   set counter 20
   while {[file exists $lockfile]} {
      incr counter -1
      if {$counter <= 0} {
         file delete -force $lockfile
      } ;# stuck lockfile
      after 333 ;
      after 333 ;
      after 333 ;
   }
   file delete -force $lockfile
}

# wait if file is locked, then lock file while adding alert

checklock 
set lock [open $lockfile w] ; puts $lock "" ; close $lock

set f [open /home/jim/.alerts a]
puts $f [lindex $argv 0]
close $f
file delete -force $lockfile

I could shorten both scripts by moving the checklock procedure to its own file, but for tiny stuff like this, it's not worth it (to me...I just use cut/paste like the above for quick hacks like this). This next one is called doalerts, and it does the real work (it's launched from an xterm, or terminal if you use that command line).

#!/usr/local/bin/wish8.4

set home /home/jim
set say /home/jim/bin/speak
set alertsfile $home/.alerts
set lockfile $home/.alertlock

cd $home

proc checklock {} {
   global lockfile

   if {![file exists $lockfile]} { return }
   set counter 20
   while {[file exists $lockfile]} {
      incr counter -1
      if {$counter <= 0} {
         file delete -force $lockfile
      } ;# stuck lockfile
      after 333 ;
      after 333 ;
      after 333 ;
   }
   file delete -force $lockfile
}


proc handle_alerts {} {
   global say alertsfile lockfile
   set lock [open $lockfile w] ; puts $lock "" ; close $lock
   set f [open $alertsfile r]
   set alertlist [split [read $f] \n]
   close $f

   foreach alert $alertlist { exec $say $alert }
   file delete $alertsfile
   file delete $lockfile
}


while {1} {
   after 333 ;
   after 333 ;
   after 333 ;
   if {[file exists $alertsfile] && ![file exists $lockfile]} {
      handle_alerts
   }
}

Simply put, it waits (again, max 20s) for the lock file to be removed, it it exists, then opens the file, reads it (splitting it into lines, as each alert is on its own line), closes it, and then uses a TTS program (espeak) to read the alert(s). Then it deletes the lock file (~/.alertlock) and the alerts file (~/.alerts).

2
  • 1
    Which script are you running exactly?
    – confetti
    Commented Aug 26, 2018 at 3:49
  • Why did the example usage before the script mention GoFundMe? I could have just as easily picked any other example from that procmail rules file ... I simply chose the one on top. That's it. Just the example I picked right from the top of the file.
    – GTbrewer
    Commented Aug 26, 2018 at 17:25
0

You may need to initialize sound in crontab temporary shell to get sound.

So it is better to put a root script in crontab and then in the script initialize audio to get sound.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .