OS
info:
uname -a
Linux debian 5.10.0-18-amd64 #1 SMP Debian 5.10.140-1 (2022-09-02) x86_64 GNU/Linux
I want to play music at reboot.
sudo crontab -e
@reboot /usr/bin/sleep 200;/usr/bin/mplayer /home/debian/welcome.mp3
No music play ,check cron log to see what happened:
sudo journalctl -u cron | grep -e "root" |grep -e mplayer -A 3
Oct 17 20:07:46 debian CRON: (root) CMD (/usr/bin/sleep 200;/usr/bin/mplayer /home/debian/welcome.mp3)
Oct 17 20:11:07 debian CRON: pam_unix(cron:session): session closed for user root
The cmd in crontab starts at Oct 17 20:07:46,closed the session at Oct 17 20:11:07,almost 200seconds!
import datetime
start = datetime.datetime(2022, 10, 17, 20, 7, 46)
end = datetime.datetime(2022, 10, 17, 20, 11, 7)
end-start
datetime.timedelta(seconds=201)
It means that /usr/bin/sleep 200
executed ,but /usr/bin/mplayer /home/debian/welcome.mp3
never start ,why?
Without /usr/bin/sleep 200
in crontab,the /usr/bin/mplayer /home/debian/welcome.mp3
only last 7 seconds!It is a 5 minutes long music!
Oct 17 20:04:50 debian CRON: (root) CMD (/usr/bin/mplayer /home/debian/welcome.mp3)
Oct 17 20:04:57 debian CRON: pam_unix(cron:session): session closed for user root
Update to create cron with a regular user,the same log :
Oct 17 21:37:26 debian CRON: (debian) CMD (/usr/bin/sleep 200;/usr/bin/mplayer /home/debian/welcome.mp3)
Oct 17 21:40:48 debian CRON: pam_unix(cron:session): session closed for user debian
Same action ,from start to end ,it last 202 seconds,almost 200 seconds.
Update for adding a mplayer's log.
Oct 17 22:25:11 debian CRON: (debian) CMD (/usr/bin/sleep 200;/usr/bin/mplayer /home/debian/welcome.mp3 2>/tmp/mplayer.reboot.log)
Oct 17 22:28:33 debian CRON: pam_unix(cron:session): session closed for user debian
cat /tmp/mplayer.reboot.log
do_connect: could not connect to socket
connect: No such file or directory
Failed to open LIRC support. You will not be able to use your remote control.
AO: [pulse] Init failed: Connection refused
Failed to initialize audio driver 'pulse'
[AO_ALSA] alsa-lib: pcm_hw.c:1715:(snd_pcm_hw_open) open '/dev/snd/pcmC0D0p' failed (-2): No such file or directory
[AO_ALSA] alsa-lib: pcm_dmix.c:1075:(snd_pcm_dmix_open) unable to open slave
[AO_ALSA] Playback open error: No such file or directory
Failed to initialize audio driver 'alsa'
[AO SDL] Unable to open audio: No available audio device
Failed to initialize audio driver 'sdl:aalib'
Could not open/initialize audio device -> no sound.
Check the file:
file /home/debian/welcome.mp3
/home/debian/welcome.mp3: Audio file with ID3 version 2.4.0, contains:MPEG ADTS, layer III, v1, 64 kbps, 48 kHz, Stereo
THe playback hardware devices:
aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: Generic [HD-Audio Generic], device 3: HDMI 0 [HDMI 0]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 0: Generic [HD-Audio Generic], device 7: HDMI 1 [HDMI 1]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 0: Generic [HD-Audio Generic], device 8: HDMI 2 [HDMI 2]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 2: Generic_1 [HD-Audio Generic], device 0: ALC662 rev3 Analog [ALC662 rev3 Analog]
Subdevices: 0/1
Subdevice #0: subdevice #0
card 2: Generic_1 [HD-Audio Generic], device 1: ALC662 rev3 Digital [ALC662 rev3 Digital]
Subdevices: 1/1
Subdevice #0: subdevice #0
Asked by showkey
(499 rep)
Oct 17, 2022, 01:32 PM
Last activity: Oct 21, 2022, 03:40 PM
Last activity: Oct 21, 2022, 03:40 PM