0

I wrote a naive script to report time hourly by playing bell.

#!/usr/bin/python3
from pydub import AudioSegment
from pydub.playback import play

bell_sound = AudioSegment.from_wav("/home/me/Music/audio/bell.wav")
play(bell_sound)

Change mode u+x

Set cron to implement it hourly (Test it very minute)

*/1 6-23 * * * /home/gaowei/Music/src/report_time.py &> /\ dev/null

Then check from the syslog that it is correctly executed

Jul 10 23:28:01 alpha CRON[10228]: (me) CMD (~/Music/src/report_time.py &> /dev/null)
Jul 10 23:29:01 alpha CRON[10242]: (me) CMD (~/Music/src/report_time.py &> /dev/null)
Jul 10 23:30:01 alpha CRON[10271]: (me) CMD (~/Music/src/report_time.py &> /dev/null)

However, why did it silence and mute even thought it is implemented.

Updated, it works as expected manually

$ ./report_time.py 
Input #0, wav, from '/tmp/tmpn6zo0wya.wav':   0KB sq=    0B f=0/0   
  Duration: 00:00:01.62, bitrate: 176 kb/s
    Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 11025 Hz, 1 channels, s16, 176 kb/s
   1.43 M-A: -0.000 fd=   0 aq=    0KB vq=    0KB sq=    0B f=0/0   

updated:

enter image description here

and other commands does not work either

## Report time 2
*/10 6-23 * * *  cvlc /home/me/Music/audio/bell.wav &\
> /dev/null

*/1 6-23 * * *  vlc /home/me/Music/audio/bell.wav &> \
/dev/null

-UUU:----F1 crontab Bot L40 (Fundamental) ----- (No changes need to be saved)

AbstProcDo
  • 19,953
  • 19
  • 81
  • 138
  • Does the script work as expected if you run it manual? – 0stone0 Jul 10 '19 at 15:42
  • yes, see my update. @0stone0 – AbstProcDo Jul 10 '19 at 16:05
  • Does the crontab runs as the same user that can run the script manual? Maybe the crontab user cant access the file. See [fixing the crontab user](https://stackoverflow.com/questions/8475694/how-to-specify-in-crontab-by-what-user-to-run-script). Otherwise, try to capture the 'output' `*/1 6-23 * * * /home/gaowei/Music/src/report_time.py > /tmp/res.txt 2>&1` – 0stone0 Jul 10 '19 at 16:19
  • It might be strange limit on function of crontab @0stone0 – AbstProcDo Jul 10 '19 at 16:30
  • Try adding the `python` path in the crontab. `*/1 6-23 * * * /usr/bin/python /home/gaowei/Music/src/report_time.py` – 0stone0 Jul 10 '19 at 16:41
  • @Algebra Maybe I am too unexperienced but what do you mean by `&>`? If you want to redirect the output just use `>`. **UPD**: I think I understood that you wanted separately `&` and `>`. You need to have a space there `*/1 6-23 * * * /home/gaowei/Music/src/report_time.py & > /dev/null` – CrafterKolyan Jul 10 '19 at 16:43

1 Answers1

0

Same problem as mine, and this answer solved my problem.

First, run id your_user_name to get your UID.

Then, modify your crontab entry from

*/1 6-23 * * * /home/<your_user_name>/Music/src/report_time.py &> /dev/null

to

*/1 6-23 * * * XDG_RUNTIME_DIR=/run/user/<your UID> /home/<your_user_name>/Music/src/report_time.py &> /dev/null

If everything goes right, the problem will be solved.

TheEagle
  • 5,808
  • 3
  • 11
  • 39